Thread: extern array definition

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    66

    extern array definition

    Problem:

    FILE1.C:
    Code:
    int foo[100];
    FILE2.C:
    Code:
    extern int foo[20];
    foo[30]=1;

    Will the size in FILE2.C be ignored since the allocation is 100 not 20?

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    try compiling it and see what happens.

    i honestly don't know the result on this one, although i'm guessing it will print an error in file2.c; because it doesnt know whats in file1.c when it's assembling file2.c. and even if there is no error there there might be errors when you run the linker or your compiled program.
    hello, internet!

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Will the size in FILE2.C be ignored since the allocation is 100 not 20?
    Yes

    Normally, I would write
    extern int foo[];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  3. array of pointers/pointer arithmetic
    By tlpog in forum C Programming
    Replies: 18
    Last Post: 11-09-2008, 07:14 PM
  4. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM