-4

Here is the structure i wrote

#define struct_macro(struct_type_name,struct_name) \
typedef struct struct_type_name                    \
{                                                  \
   int a;                                          \
   char b;                                         \
} struct_name

this is throwing QAC error with '()' missing.

But with '()' there is compilation error.

#define struct_macro(struct_type_name,struct_name) \
typedef struct struct_type_name                    \
{                                                  \
   int a;                                          \
   char b;                                         \
} (struct_name)

Is there any workaround??

rakshi
  • 23
  • 6
  • Did you cut and paste your example into your post and there are multiple typos. – SPlatten Jan 04 '19 at 09:57
  • edited as suggested, thank you! – rakshi Jan 04 '19 at 10:49
  • Have you got this resolved? If not, I think it would help if you created an MCVE ([MCVE]) which showed code where you define the macro and where you use it. Ensure that the code generates the error you're seeing. Normally, you should put at least a space between the `)` of the function-like macro name and arguments and the replacement text. When you have backslash-newline, there is no space. However, I don't think that should be the problem (but it might be). – Jonathan Leffler Jan 04 '19 at 17:01
  • As currently written, you can't use the macro twice in a single scope because it creates the same structure tag each time because you've got a typo in `strct_type_name` (vs `struct_type_name`). – Jonathan Leffler Jan 04 '19 at 17:02

1 Answers1

0
#define struct_macro(struct_type_name,struct_name) typedef struct struct_type_name\
{\
   int a;\
   char b;\
} struct_name\
0___________
  • 60,014
  • 4
  • 34
  • 74
  • @rakshi you have many spelling errors in the code you have provided - so I am not surprised that you have a problem compiling and QAing it. – 0___________ Jan 04 '19 at 11:27
  • i corrected as suggested, thank you. Any possible solutions are appreciated. – rakshi Jan 05 '19 at 04:06