Results 1 to 7 of 7

Thread: [Resolved] confused about extern

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Resolved [Resolved] confused about extern

    Hi,
    First off, I have had no formal C training. I learned what I know of C from a book, "Absolute Beginner's Guide to C" and picked up other bits here and there. Also, my application is embedded, not run on a PC. I've written maybe a dozen programs for embedded applications over the last 2 or 3 years.

    My question is on the use of the word extern in a declaration. I'm confused about how and when its used. I understand that it is used for variables that are not local to a function. My confusion comes from having used global variables for some time now and I've never needed to use it.

    Usually, when I need global variables, I declare them before Main, outside of any function. If the program is large and I need many of them, I put them into a header file and include the header file in the program before the Main function. My understanding is that extern would be used before global variables that are used in other code files, but I put the declaration in a separate file (header file) and include it and it works without error.

    I'm wondering if my confusion stems from the fact that when I include all my code files into main, that the compiler makes one big file out of them, and so I don't need extern? Perhaps, if I didn't include the code files, but just listed them as part of the project, I would need extern? I would appreciate any clarity that anyone could give.

    Thanks.
    Last edited by rickford66; Apr 27th, 2011 at 09:31 AM.

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