0

I would like to do a #define which contains a #pragma directive but I got the following error. Any idea?

#define FunctionPar_Begin  typedef struct fpar { #pragma pack(4)

error C2121: '#': invalid character: possibly the result of a macro expansion
ChrisMM
  • 8,448
  • 13
  • 29
  • 48
Emanuele
  • 1
  • 1
  • 1
    You should be able to use [`_Pragma("pack(4)")`](https://en.cppreference.com/w/cpp/preprocessor/impl). – Eljay Oct 13 '22 at 17:12

1 Answers1

1

The one you probably want:

#define FunctionPar_Begin  typedef struct fpar { _Pragma("pack(4)")

MSVC also allows for:

#define FunctionPar_Begin  typedef struct fpar { __pragma(pack(4))

Clang/gcc also allow:

#define FunctionPar_Begin  typedef struct fpar { __attribute__((packed, aligned(4)))
robthebloke
  • 9,331
  • 9
  • 12