Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Malaclypse

C semantics question

Recommended Posts

I've got a question regarding C semantics. The use of extern for both variables and functions is quite inconsistent in the code.

 

From many frameworks and applications I saw, I know that it's use is mandatory for libraries but not for applications, as they generally don't really export much, but imho it's considered good style to also use it with apps.

 

So my question? Can someone post a short comment on this topic? Does it make sense to use or not use this modifier in the clients source?

 

Reason is, I'm currently in the cleanup of the code (see my other thread in programming forum about this topic) and was thinking of adding the extern modifiers where they are missing.

 

Thanks in advance

Share this post


Link to post
Share on other sites

IIRC, functions are by default extern, so there's no need to declare them as such. Variables should only be declared extern if they're used in more than one object file, but they shouldn't end up in a header file if that's not the case anyway.

 

Anyway, I'm not an expert on these things, so if someone more knowledgeable wants to correct me, go ahead.

Share this post


Link to post
Share on other sites

When you see "extern int" it does not mean "declare an int and make it available outside this file", it means "there is an int by this name declared in another file, use it instead of creating a new variable". Whenever you see an "extern" variable, it should mean that the file in question is trying to access a variable by that name that is declared in another file.

Share this post


Link to post
Share on other sites

^

And yes, functions prototypes are externs already.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×