I think to demonstrate the usage of extern, we should use more than one compile unit (cpp file) to demonstrate, right?
extern "C"
Collapse
X
-
-
Hi oler1s,
Why it is needed to use extern even if we are in the same cpp file? Any more description please?
(I think extern is useful for cross-compile unit cross-reference usage, if only in one compile unit, is it very helpful?)
Originally posted by oler1sNot necessary, if you understand the concepts of linkage. Of course, the assumption is that you do your reading and actually understand the background material. Otherwise, you have to rely on unnecessarily complicated demonstrations to cover up such lack of knowledge.
regards,
GeorgeComment
-
Why it is needed to use extern even if we are in the same cpp file?
(I think extern is useful for cross-compile unit cross-reference usage, if only in one compile unit, is it very helpful?
But why are you having fundamental issues understanding it, when you declare your understanding on Cboard, continue with a second thread at CodeGuru, and yet another on a Usenet group?Comment
-
Hi oler1s,
Are there any practical benefits if we use extern keyword to qualify a variable defined in the same cpp file? This is my question.
Originally posted by oler1sWhat do you mean by that question? You use extern to specify external linkage. That is you are simply the declaring the existence of something, and indicating that the actual definition is in some other source file or library. You use extern if that's what you need to indicate.
Again, let me repeat myself. If you need something to have external linkage, it should either implicity or explicitly be declared as extern. For example, you don't indicate extern with function declarations, because it is implicitly implied. You do with variables, because you need to say so explicitly. IF something doesn't need external linkage, you don't need to use the extern keyword. Just because the extern keyword exists doesn't mean you need to use it, you realize?
But why are you having fundamental issues understanding it, when you declare your understanding on Cboard, continue with a second thread at CodeGuru, and yet another on a Usenet group?
regards,
GeorgeComment
-
Originally posted by George2Hi oler1s,
Are there any practical benefits if we use extern keyword to qualify a variable defined in the same cpp file? This is my question.
regards,
George
You continue to ask the same question that would have been answered if you would have investigated more.
But in answer to your question, it depends on the scope of your variable.Comment
Comment