Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C struct creation error does not name a type

Tags:

c

struct

I am just trying to set up a simple recursive struct without too much knowledge of C (have to learn somehow)

here is my make compile line

g++ -o cs533_hw3 main.c

here is my code

typedef struct Node Node;

struct Node
{
    int texture;
    float rotation;
    Node *children[2];
};

Node rootNode;
rootNode.rotation

Here is my error on the last line

error: 'rootNode' does not name a type
like image 452
Justin Giboney Avatar asked Dec 01 '22 21:12

Justin Giboney


1 Answers

Code has to be in functions in C. You can declare variables at the global scope, but you can't put statements there.

Corrected example:

typedef struct Node Node;

struct Node
{
    int texture;
    float rotation;
    Node *children[2];
};

Node rootNode;

int main(void)
{
    rootNode.rotation = 12.0f;
    return 0;
}
like image 190
Carl Norum Avatar answered Dec 09 '22 13:12

Carl Norum