typedef to store pointers in C

Posted by seriouslion on Stack Overflow See other posts from Stack Overflow or by seriouslion
Published on 2010-05-23T17:41:21Z Indexed on 2010/05/23 17:50 UTC
Read the original article Hit count: 149

Filed under:
|
|

The Size of pointer depends on the arch of the machine.

So sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int)

I want to have a custom data type which is either int or long int depending on the size of pointer.

I tried to use macro #if, but the condition for macros does not allow sizeof operator.

Also when using if-else, typedef is limited to the scope of if.

if((sizeof(int)==sizeof(int *)){
  typedef int ptrtype;
}
else{
  typedef long int ptrtype;
}
//ptrtype not avialble here

Is there any way to define ptrtype globally?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointers