Size of extern int x;

S

skishorev

Hi,

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

Vladimir Oka

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).
 
R

Richard Heathfield

(e-mail address removed) said:
If i declared extern int x; in linux environment. what is the size?

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

jaysome

(e-mail address removed) said:


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.
 
B

Barry Schwarz

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top