Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef,#define

Tags:

c

macros

typedef

Can anybody explain the difference between

#define int* char

and

typedef int* char;
like image 642
soma sekhar Avatar asked Jan 25 '26 10:01

soma sekhar


1 Answers

There's no difference because both are illegal.

int* isn't a valid identifier for a macro, and even if you put a space in, neither is int, because it's a keyword and reserved. Even if you switched it to your likely intended #define char int*, it fails for the same reason.

And you cannot redefine the type char, so the typedef is a bust.


The difference, had you given examples that were legal, is that #define is a preprocessing directive. It only does textual replacement, before the compiling stage. Contrarily typedef defines a new type, and that new type identifier respects "the rules" just like any other type.

like image 104
GManNickG Avatar answered Jan 28 '26 04:01

GManNickG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!