tag:blogger.com,1999:blog-2420869991974935734.post1489044749801357454..comments2023-07-02T17:04:56.386+02:00Comments on Krister Walfridsson’s old blog: Pointer casts in CKrister Walfridssonhttp://www.blogger.com/profile/02591279630933941271noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2420869991974935734.post-91588750407624151592016-05-26T15:35:22.971+02:002016-05-26T15:35:22.971+02:00GCC does in most cases only warn for things that m...GCC does in most cases only warn for things that may be problematic in reality, and this works on "all" machined used in reality.<br /><br />So this is the same as the "missing" warning for the UB in your printfs -- printf %p is UB unless the argument is void*, <br />so you would need to write<br /> printf("p=%p\n", p);<br />as<br /> printf("p=%p\n", (void*)p);<br />But GCC does not warn about this either, even though -Wall is supposed to check that the printf arguments have the appropriate type, as this always work in reality, and users would be annoyed by these useless (but correct!) warnings...Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-20297412348815577052016-05-25T10:23:14.795+02:002016-05-25T10:23:14.795+02:00I tried this under Ubuntu and could not get gcc to...I tried this under Ubuntu and could not get gcc to complain..:<br />(-Wall -Wextra -Wconversion)<br />typedef void (*callback)(int, char);<br /><br />void func1(int i, char c) {<br /> printf("%s %d,%c\n", __func__, i, c);<br />}<br /><br />int main(int argc, const char *argv[])<br />{<br /> callback cb = func1;<br /> int i = (int)cb;<br /> printf("cb=%p\n", cb);<br /> printf("i=0x%x\n", i);<br /> int* p = (int*)cb;<br /> printf("p=%p\n", p);<br /><br />...<br />}Bas van den Berghttps://www.blogger.com/profile/10302109105653515249noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-63017027684509777652016-03-22T22:28:09.417+01:002016-03-22T22:28:09.417+01:00I had an alignment problem with a MSP430 based wir...I had an alignment problem with a MSP430 based wireless node: http://stackoverflow.com/questions/20410495/ti-cc2530-convert-a-float-to-uint8-for-sending-and-then-convert-back-to-floaAlex Pacinihttps://www.blogger.com/profile/13304951646877405715noreply@blogger.com