CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    extern sample in MSDN

    Hello everyone,


    I think in practical experience, extern is useful only when we have more than one compile unit (cpp file) and making cross-reference between compile units.

    In the MSDN extern sample,

    http://msdn2.microsoft.com/en-us/library/0603949d.aspx

    It only uses one source file (compile unit) to demonstrate the usage of extern, is it correct and practical?


    thanks in advance,
    George

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: extern sample in MSDN

    In the MSDN extern sample,
    There are two code examples in that MSDN entry.

    It only uses one source file (compile unit) to demonstrate the usage of extern, is it correct and practical?
    What do you mean by "practical"? Code examples are typically not "practical", but intended either for demonstration or to be adapted for actual use.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: extern sample in MSDN

    Thanks laserlight,


    I mean this sample. Any comments to my original question?

    Code:
    // specifying_linkage1.cpp
    int i = 1;
    void other();
    
    int main() {
       // Reference to i, defined above:
       extern int i;
    }
    
    void other() {
       // Address of global i assigned to pointer variable:
       static int *external_i = &i;
    
       // i will be redefined; global i no longer visible:
       // int i = 16;
    }
    Quote Originally Posted by laserlight
    There are two code examples in that MSDN entry.


    What do you mean by "practical"? Code examples are typically not "practical", but intended either for demonstration or to be adapted for actual use.

    regards,
    George

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured