3 ms·
Sorry, this post wasn't meant to be about the cast. You can cast it -- it's not that line itself that matters. It's that pointers and integers can take arbitrar
by Locke1689 16y ago
Sorry, this post wasn't meant to be about the cast. You can cast it -- it's not that line itself that matters. It's that pointers and integers can take arbitrary values in C. After you do the cast is what really matters. In C you have to be aware of the semantics of your code at all times because the weak typing will not save you.
- pvg 16y agoWell, to be honest, I really don't exactly know what we're talking about anymore. What the parent was saying is that you have to be super careful with the types of pointers and integers because C will let you use them interchangeably. This is obviously not true, despite the rain of inexplicable upvotes. He then has a pointer arithmetic example which is really not so much about typing but about understanding pointer arithmetic. Of course C will also let you treat pointers as integers and vice versa, especially if you explicitly tell it to, by casts. But in the general case, it will whine and, in fact, reducing unnecessary whining is one of the reasons to not go hog-wild with useless typedefs. I'm not sure how we got here, I think one person here doesn't know C very well and the rest of us got into a little and completely tangential C nerdfest.
- Locke1689 16y agoOf course C will also let you treat pointers as integers and vice versa, especially if you explicitly tell it to, by casts. But in the general case, it will whine and, in fact, reducing unnecessary whining is one of the reasons to not go hog-wild with useless typedefs. I'm not sure how we got here, I think one person here doesn't know C very well and the rest of us got into a little and completely tangential C nerdfest. Hmm that's fair. I also think I started entering kernel-dev mode where you have to carefully watch everything that you do, whereas most people probably have C experience with the benefit of things like the C standard library. For whatever it's worth, I was seeking to reference the idiom where you store an address as an integer in order to do some hardware operations. You have to keep semantic knowledge of that integer as really being a pointer even though it's, for the moment, stored as an integer. In cases like this the C compiler is no help whatsoever.