Error creating C structure does not indicate type

I'm just trying to create a simple recursive structure without too much knowledge of C (I need to learn something)

here is my make compilation 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 mistake on the last line

 error: 'rootNode' does not name a type 
+4
source share
2 answers

The code must be in functions in C. You can declare variables in the global scope, but you cannot 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; } 
+15
source

It looks right. But you probably wanted to do something with rootNode.rotation?

 Node rootNode; memset(&rootNode, 0, sizeof(rootNode)); // zero everything there rootNode.rotation = .5f; 
0
source

Source: https://habr.com/ru/post/1469035/


All Articles