external variables

This is a discussion on external variables within the C Programming forums, part of the General Programming Boards category; I am trying to use external variables in a fairly simple program. but on build time I am reciving an ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    Cool external variables

    I am trying to use external variables in a fairly simple program. but on build time I am reciving an warnigs and errors
    • warnig:benign redefinition of type
    • error:intializer is not a constant


    what I have done is use a constant foo let us say. declared foo in const.h
    Code:
    extern int foo;
    then in const.c have said
    Code:
     
          int foo;
          int m=3;
    foo = 140 *m;
    reciving the error.. I have no clue y it don't work .. any help is good cheers

  2. #2
    btq
    btq is offline
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    you can't do it like that..
    the external keyword is just if the int is in another source-file..if you put it in the header it's actually in the same file...uhmm...basically you get:

    const.c:
    external int foo;
    ...
    int foo;

    which would cause a redefinition error...(if you include const.h in const.c)

    /btq
    ...viewlexx - julie lexx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. Overloaded Operator Causes Unresolved External Symbol
    By mikeman118 in forum C++ Programming
    Replies: 11
    Last Post: 03-03-2008, 03:40 PM
  4. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 03:46 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 01:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21