top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How will I identify MYINT is #define or typedef ??

+5 votes

In a large project . There is a lots of header files included one another and I do not know the header file in which MYINT is define.

How will I know that MYINT is

#define MYINT int


typedef int MYINT
posted Oct 17, 2013 by Vikas Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Try this :
1) do #defint to MYINT If no error comes means MYINT is #define.

NO error

#define MYINT int
#define MYINT int

main() { }

2) do typedef to MYINT If error comes means MYINT is typedef.

typedef int MYINT;
typedef int MYINT;

main() { }

define_typedef.c:3: error: redefinition of typedef âMYINTâ
define_typedef.c:2: error: previous declaration of âMYINTâ was here

Same #define is allowed but typedef is not allowed.

answer Oct 18, 2013 by Anuj Yadav
0 votes

define is preprocessor command while typedef is compiler job, when you have a file (or coming via include) with both are present the code will not compile as by the time it reaches compiler the MYINT would have been replaced to int so compiler will see it as "typedef int int". So your problem will be solved at compile time itself.

See the following program

#define MYINT int
typedef int MYINT;

   MYINT a;
Line 2: error: two or more data types in declaration specifiers
Line 2: warning: useless type name in empty declaration
answer Oct 18, 2013 by Luv Kumar
My question that you are using MYINT.
How will you know it is typedef or #define.
Similar Questions
+3 votes

typedef int *ptr;
ptr p1, p2;

In this P2 is Integer Pointer or Integer?

0 votes
#define MY_STRUCT
typedef struct{ 
} my_struct;

Above code is giving me error (MY_STRUCT) is not working as expected, Looks that some silly mistake, please point out as I have wasted many hours?

Sorry for hiding my identity?