No, It's Not OK

The code below is broken in a subtle way. There’s no way to know that ptr is aligned on a boundary that your CPU architecture may require. And I don’t think there is any way to know until runtime. Oh, C, I love thee and loath thee!

printf("%u", *(unsigned int *)ptr);
Advertisements
This entry was posted in Code, Geek. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s