p = q + offset
When you really meant: *p = *q + offset
Hence, careful understanding of the type of p and q are important, so you can decide what you really mean.Consider:
unsigned long addr_t = &x;
This is not only completely legal ANSI C but is also idiomatic in kernel development.warning: initialization makes integer from pointer without a cast
Without explicit casts, the compiler won't let you confuse pointers with integers without a warning or an error.
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.
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.
$ cat test.c
int x;
unsigned long addr_t = &x;
$ cc test.c
test.c:2: warning: initialization makes integer from pointer without a castThe fact that the Linux kernel works on such disparate architectures also works against your point.
If you know how to make
__asm__ __volatile__(...)
portable I'd love to hear it.
A C compiler will generally keep you from forgetting that just fine.