Fiction

Fiction L
A Fake Internet Presence,
since 1994

 Home
 TidBits
 BLong
   Source
     GBuffy
     Mutt
     ClearSilver
     Python
     PyApache
   PalmOS Tools  

What the hell is type punning?
2004-06-18

All of a sudden, everyone is complaining that clearsilver doesn't compile, or at least gives bad sounding warnings about type-punning. I don't even know what that is, but all of the discussions I've read make it sound like I'm the only one who doesn't know what that is. Apparently, I missed a memo. Here's a usenet summary that says "Type punning generally means treating an object, particularly a pointer, as an object of a different type." for the example: (int*)ptr_to_void.

The problem seems indemic to the my generic collections, where I get data out of the collection by passing in a ptr to void *. Apparently, this doesn't work:

  struct tm *foo;
  uListGet(mylist, 1, (void **)&foo);
but this does:
  struct tm *foo;
  void *ptr;
  uListGet(mylist, 1, &ptr);
  foo = ptr;
That's annoying. This also compiles:
  struct tm *foo;
  uListGet(mylist, 1, (void *)&foo);
which I'm not sure why. You can't do &(void *)foo, so maybe its just an ordering thing?

Here's off to change all the calls in my code. Ugh.


RSS Feed
Click for San Francisco, California Forecast

Personal
·About Brandon
·Fediverse
·Twitter
·Instagram
·Resume
·Programming

Friends & Rants
·Clong Way From Home
·Wingedpig
·Unsolicited Dave
·Jason Lindquist
·Ben Gross
·Alan Braverman

Comics
·Sluggy Freelance
·XKCD
·Questionable Content
·Least I Could Do
·Saturday Morning Breakfast Cereal


Copyright (C) 2020 Brandon Long. All Rights Reserved.
[email protected] / Terms of Service

The "I work for a big public company" disclaimer:
The views expressed on these pages are mine alone and not those of my employer.
I am not now, nor have I ever been employed to speak for anyone.
Well, except my own company, but that's gone now.