Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXIT_ERROR macro requires do-while() #9

Open
not-kaz opened this issue Jul 28, 2022 · 3 comments
Open

EXIT_ERROR macro requires do-while() #9

not-kaz opened this issue Jul 28, 2022 · 3 comments

Comments

@not-kaz
Copy link

not-kaz commented Jul 28, 2022

Hi,

I believe the EXIT_ERROR/EXIT_RETURN macros should be wrapped in a do-while(0) loop.
At the moment the macro cannot be used in an if/else statement and the trailing semi-colon is unnecessary.

#define EXIT_ERROR(...) do { fprintf(stderr, VA_ARGS); exit(1) } while (0)

@Falconerd
Copy link
Owner

Hey @not-kaz can you let me know your OS and terminal? I haven't got any issue on Windows with this macro, inside or outside of an if/else statement.

@not-kaz
Copy link
Author

not-kaz commented Aug 14, 2022

Hey @Falconerd,

Easiest example I've managed to find is in no-braces if/else statements.

if (!file_vertex.is_valid)  
    ERROR_EXIT("Error reading shader: %s\n", path_vert);  
else  
    fprintf(stdout, "Success\n"); 

On gcc this fails as 'else without previous if' and the ';' on the macro is regarded as an empty statement.

I'll just provide a quick google search result to hopefully explain better than me :)
https://hownot2code.wordpress.com/2016/12/05/do-while-0-in-macros/

@Falconerd
Copy link
Owner

Thanks, I will take a look :)

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

No branches or pull requests

2 participants