Search code examples
cvisual-studiostructundefined-symbol

C struct initialization with macro value


I know C++ and I am learning C. I would like to define nullptr as NULL, but when I initialize a struct using brackets it causes an error and says expected '}'. I'm using the visual studio compiler and a sample of my code is bellow:

#define nullptr NULL;

typedef struct
{
    int data;
    struct Node* next;
} 
Node;

//works fine
Node myNode1;
myNode1.data = 1;
myNode1.next = nullptr;

//works fine
Node myNode2 = {1, NULL};

//error E0067   expected a '}'
Node myNode3 = {1, nullptr };

Solution

  • Define nullptr as

    #define nullptr NULL
    

    with no trailing ;.