Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Size of extern int x; (http://www.velocityreviews.com/forums/t442782-size-of-extern-int-x.html)

skishorev@yahoo.co.in 05-16-2006 09:30 AM

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


Chris McDonald 05-16-2006 09:32 AM

Re: Size of extern int x;
 
skishorev@yahoo.co.in 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.

skishorev@yahoo.co.in 05-16-2006 09:43 AM

Re: Size of extern int x;
 
Hi,

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


Vladimir Oka 05-16-2006 09:52 AM

Re: Size of extern int x;
 

skishorev@yahoo.co.in 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).


Richard Heathfield 05-16-2006 10:17 AM

Re: Size of extern int x;
 
skishorev@yahoo.co.in 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)

jaysome 05-17-2006 10:03 AM

Re: Size of extern int x;
 
On Tue, 16 May 2006 10:17:02 +0000, Richard Heathfield
<invalid@invalid.invalid> wrote:

>skishorev@yahoo.co.in 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

Barry Schwarz 05-21-2006 11:23 AM

Re: Size of extern int x;
 
On Wed, 17 May 2006 03:03:41 -0700, jaysome <jaysome@spamcop.net>
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


All times are GMT. The time now is 04:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57