extern "C"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #16
    I think to demonstrate the usage of extern, we should use more than one compile unit (cpp file) to demonstrate, right?
    Not 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.

    Comment

    • George2
      New Member
      • Dec 2007
      • 200

      #17
      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 oler1s
      Not 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,
      George

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #18
        Why it is needed to use extern even if we are in the same cpp file?
        What 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.

        (I think extern is useful for cross-compile unit cross-reference usage, if only in one compile unit, is it very helpful?
        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?

        Comment

        • George2
          New Member
          • Dec 2007
          • 200

          #19
          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 oler1s
          What 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,
          George

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #20
            Originally posted by George2
            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.

            regards,
            George
            If you took the time to read about what extern means and try to learn from the text. Then ask questions about the text, for example say, "I don't understand what this text means when it says "blah, blah blah blah, blah", we might be more willing to help you.

            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

            Working...