Size of extern int x;

Discussion in 'C Programming' started by skishorev@yahoo.co.in, May 16, 2006.

  1. Guest

    If i declared extern int x; in linux environment. what is the size?
    , May 16, 2006
    #1
    1. Advertising

  2. writes:

    >If i declared extern int x; in linux environment. what is the size?


    Why do you suspect that it'll be anything other than sizeof(int) ?

    --
    Chris.
    Chris McDonald, May 16, 2006
    #2
    1. Advertising

  3. Guest

    Hi,

    I am asking that whether it will create memory at the time of
    decalaration of extern int x;
    , May 16, 2006
    #3
  4. Vladimir Oka Guest

    wrote:
    > I am asking that whether it will create memory at the time of
    > decalaration of extern int x;


    Quote context. Read <http://cfaj.freeshell.org/google/>.

    You did not make yourself clear the first time.

    For the `extern` declaration, no memory need be allocated, as it just
    tells the compiler not to worry about it, as `x` is guaranteed to exits
    (as a variable of type `int`) somewhere else. Exactly where this
    `somewhere else` is physically, will be discovered at link phase (if
    not, linking will fail).
    Vladimir Oka, May 16, 2006
    #4
  5. said:

    > If i declared extern int x; in linux environment. what is the size?


    No storage is reserved, so there isn't a size.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, May 16, 2006
    #5
  6. jaysome Guest

    On Tue, 16 May 2006 10:17:02 +0000, Richard Heathfield
    <> wrote:

    > said:
    >
    >> If i declared extern int x; in linux environment. what is the size?

    >
    >No storage is reserved, so there isn't a size.


    One may interpret the OP's question as: "What is sizeof x?" In which
    case, the following code should answer that question.

    #include <limits.h>
    #include <stdio.h>
    extern int x;
    int main(void)
    {
    const int INT_BITS = (int)(sizeof(int) * CHAR_BIT);
    printf
    (
    "sizeof x = %d, same as sizeof(int) = %d\n",
    (int)sizeof x,
    (int)sizeof(int)
    );
    printf
    (
    "type int is %d bit%s\n",
    INT_BITS,
    INT_BITS == 1 ? "" : "s"
    );
    return 0;
    }
    int x = 0;

    If you can spot how a standard-compliant compiler will never achieve
    100% decision coverage in the above code, then you win a prize.

    --
    jay
    jaysome, May 17, 2006
    #6
  7. On Wed, 17 May 2006 03:03:41 -0700, jaysome <>
    wrote:


    snip code

    >If you can spot how a standard-compliant compiler will never achieve
    >100% decision coverage in the above code, then you win a prize.


    What does the phrase "decision coverage" mean?


    Remove del for email
    Barry Schwarz, May 21, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Matthews
    Replies:
    5
    Views:
    2,373
    tom_usenet
    Aug 2, 2004
  2. Schnoffos
    Replies:
    2
    Views:
    1,198
    Martien Verbruggen
    Jun 27, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,615
    Old Wolf
    Jan 20, 2004
  4. sinbad

    extern int *a , int a[10]

    sinbad, Aug 10, 2007, in forum: C Programming
    Replies:
    6
    Views:
    520
    Keith Thompson
    Aug 10, 2007
  5. Andre
    Replies:
    5
    Views:
    521
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page