typedef a union as a struct?
Well, I don't give myself much credit when it comes to C but I'm having a really hard time with this particular problem. Here's the bit of code I'm struggling with, it's from /usr/include/sys/socket.h
Code:
# define __SOCKADDR_ARG struct sockaddr *__restrict I think I understand the transparent union attribute. It seems like it makes it somewhat of an "abstract class" in that any variable of the same type as any member of that union will be treated as that "union's type" without casting. Conceptually that makes sense, although it seems like passing a sockaddr_in as a sockaddr would cause problems unless the user programs are the only ones manipulating the actual structs and the kernel just passes them around, which is what I expect. Beyond that, I have no idea what __restrict does, so I would appreciate it if someone could explain that to me. And maybe it's just too late at night for me, but I don't see how (or why) you would typedef a union as a struct. The only thing I can think of is that maybe since the transparent_union attribute makes the union more like a class (of structs) it needs to be "named" a struct. To help me figure this out, I tried to write a similar program (but much smaller ^_^) so I'll attach that in case I just misinterpreted something that was happening and incorporated it into my program incorrectly. Code:
#include <stdio.h> Thanks in advance. P.S. I know my variable names suck. |
Code:
switch(sizeof(boo)) I don't know if that's the issue you're looking for or not. |
No, that wasn't the issue. I know it doesn't work and why, but 1. I didn't write that function originally to use pointers and 2. I don't care what happens in that function anymore. I was originally hoping to be able to distinguish between the types in the union but then my union wasn't working so I just left that alone.
Thanks for the reply though. |
gcc -E filename.h will show you what the final result of the code is.
|
All times are GMT -5. The time now is 02:10 PM. |