Malaclypse Report post Posted March 7, 2005 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
Grum Report post Posted March 7, 2005 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
Cicero Report post Posted March 7, 2005 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
Wytter Report post Posted March 7, 2005 ^ And yes, functions prototypes are externs already. Share this post Link to post Share on other sites
Malaclypse Report post Posted March 8, 2005 Ok, the way Cicero told, is also the way I did understand this. Thanks Wytter for the info about functions Share this post Link to post Share on other sites