tj / luna

luna programming language - a small, elegant VM implemented in C
2.46k stars 148 forks source link

reserved identifier violation #59

Closed elfring closed 8 years ago

elfring commented 10 years ago

I would like to point out that identifiers like "__LUNA_AST__" and "__LUNA_TOKEN__" do not fit to the expected naming convention of the C language standard. Would you like to adjust your selection for unique names?

haneefmubarak commented 10 years ago

Perhaps it could be replaced with LUNA_AST? I can do that if anyone would like.

elfring commented 10 years ago

How do you think about to make your include guards not only standard-compliant but also really unique by appending a kind of UUID?

haneefmubarak commented 10 years ago

Solution: don't use include guards. Use


#pragma once

instead.

thehydroimpulse commented 10 years ago

@elfring using a random UUID for include guards isn't a very good idea. Conforming to a good naming scheme is.

@haneefmubarak Pragma once isn't standardized, and thus isn't guaranteed to be supported by every platform and compiler. Pragma once is used heavily on windows, but elsewhere you should stick with the standard.

haneefmubarak commented 10 years ago

@TheHydroImpulse I've actually never touched a windows system in terms of code, tbh. I do all of my work on and for Linux and OSX, and on both systems, whether using Clang or GCC, #pragma once is all I use and it works without fail.

thehydroimpulse commented 10 years ago

@haneefmubarak Just because it works doesn't mean you should use it. If you want to write standard C, use include guards.

haneefmubarak commented 10 years ago

Sometimes, you should use it, especially when it is well supported across all of the normal compilers.

http://stackoverflow.com/questions/1143936/pragma-once-vs-include-guards

thehydroimpulse commented 10 years ago

If you want to write standard C, use include guards.

Most projects (especially open source projects) tend to use include guards because they're standardized.

And if you're doing embedded stuff, include guards are the way to go period. You don't always get the fancy features of modern C compilers.

haneefmubarak commented 10 years ago

Thankfully, we're developing for full systems and not AVRs or MSPs. Using the "fancy features of modern C compilers" means less mess, less chances of screwing something up, and less ugly guards, all at no cost.

thehydroimpulse commented 10 years ago

If you want to write standard C, use include guards.

i.e., if you use #pragma once, you're not writing standard C. Is that a bad thing? Maybe, or maybe not.

It's really a non-issue for your projects. But it certainly can be for other people's. Many popular open source C projects use standardized stuff, so they can be advertised as ANSI C and the like.

haneefmubarak commented 10 years ago

Here's a little something: it works perfectly fine with virtually all of the common compilers: GCC (properly since 2004 with GCC 3.4), Comeau, Clang, Intel, and Microsoft.

So other than being pedantic, there really isn't a reason not to use it, especially given the benefits it has, such as only being a one liner and not having to worry about naming schemes.

Further reading: http://teknicool.tumblr.com/post/19908569863/pragma-once-is-better-than-include-guards

glhrmfrts commented 8 years ago

I vote for something like LUNA_AST_H

elfring commented 8 years ago

Thanks for your improvement of affected include guards.