Skip to content

Conversation

abdorayden
Copy link

I noticed that you have to define a new structure even if you use it only once. nob_da_declare allows you to define a generic structure type in a single line instead of explicitly declaring a structure.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used practically the same macro for some time and find it neat.
As you describe here it can be used as sort of "anonymous" type. However this usage might make some compilers warn about argument types. But it works i guess.

nob_declare(int) name = {0};

void fu(nob_declare(int) * inp){
    return;
}

fu(&name);

You can typedef which solves the warnings.

 typedef nob_declare(float) Some;

 Some name = {0}; 

 void fu(Some * inp){
     return;
 }

fu(&name);

Copy link
Author

@abdorayden abdorayden Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for sharing your experience with nob_da_declare and the suggestion about using typedef to avoid warnings.

You're absolutely right-this macro effectively creates an anonymous structure, and using typedef helps maintain cleaner code and prevents compiler warnings.

And you have ability to declare and use these structures globally (outside main) is a great point -it adds flexibility in how the macro can be applied

// Declared as global variable 
nob_da_declare(int) numbers = {0};

void foo(){
    nob_da_append(&numbers , 10);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants