Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What will this C code do?

Name: Anonymous 2012-01-19 8:24

void main(){
int x=1;
printf("%d\n",x=2);
}

Name: Anonymous 2012-01-22 13:34

>>120
You mean an uninitialized variable? It would have an indeterminate value, but it would still have been allocated. If by unnamed variable you're referring to unnamed members of a struct or union, again, it would still be allocated somewhere. In the case of a flexible array member, it would have allocated duration.

Name: Anonymous 2012-01-22 13:36

>>119
And more to the point you annoying fucker...

You realize global variables have file scope by definition, right? Since they have file scope, they can't have automatic duration.

I can think of a case where a global variable doesn't have automatic duration. In other words, the variable wouldn't have an object associated with it.

Name: Anonymous 2012-01-22 13:40

>>121
You mean an uninitialized variable? It would have an indeterminate value, but it would still have been allocated.

And what happens if I don't define the variable you annoying shit? Exactly. Now again, I suggest that you actually read a book.

Name: Anonymous 2012-01-22 13:40

>>122
I said they can't have automatic duration. If you don't explicitly initialize a global variable, it's value will be 0, unless of course you only declared the variable, in which case it will just be ignored if you don't provide a definition.

Name: Anonymous 2012-01-22 13:42

>>123
Are you talking about global variables specifically? If you don't define the variable, it is just ignored, as mentioned by my previous post.

Name: Anonymous 2012-01-22 13:44

>>124
unless of course you only declared the variable, in which case it will just be ignored if you don't provide a definition.

Again, that is incorrect you moron.

Name: Anonymous 2012-01-22 13:45

>>125
No, it won't get ignored you idiot. Why don't you just shut the fuck up and write some C code since you clearly don't seem to keen on the whole reading thing.

Name: Anonymous 2012-01-22 13:49

>>126,127
If there's no definition, it can't be allocated. If you try to use that variable, your compiler will spit out an error. Why don't you take your own advice and write some C code?

Name: Anonymous 2012-01-22 13:52

>>128
If there's no definition, it can't be allocated. If you try to use that variable, your compiler will spit out an error.

That's because the compiler isn't ignoring the variable you fucking annoying stupid shit. If the compiler would have in fact ignored the variable, like what you claim, then it wouldn't have spit out an error.

Why don't you take your own advice and write some C code?

I have you annoying stupid shit.

Name: Anonymous 2012-01-22 13:53

>>128
And again, for the third time, you aren't making a clear distinction between the variable and the object. So once again, you're stupid. And once again, you have no possible future as a computer programmer.

Name: Anonymous 2012-01-22 13:58

>>129
It will be ignored. There won't be any trace of it after the program is compiled. However, if you're trying to use it, the compiler will obviously complain. Since you're so fond of the standard:
If an identifier declared with external linkage is used in an expression (other than as part of the operand of a sizeof operator whose result is an integer constant), somewhere in the entire program there shall be exactly one external definition for the identifier; otherwise, there shall be no more than one.

Name: Anonymous 2012-01-22 13:59

>>130
Waah waah waah, that's you crying like a baby.

Name: Anonymous 2012-01-22 14:00

>>128

PROTIP: Do not discuss with Kodak. He suffers from schizophrenia and urinary incontinence, which gives him a rather unpleasant attitude. The assiduous presence of such people is the worst thing which can happen to non-moderated boards.

Name: Anonymous 2012-01-22 14:01

>>131
But having something like

int foo;

isn't an expression you fucking moron.

Name: Anonymous 2012-01-22 14:04

>>131
Also you stupid fucker, in C, a statement, an expression, and an expression-statement are three different thing. Cripes you are one stupid SOB.

Name: Anonymous 2012-01-22 14:05

>>133
Do you care to help the toilet scrubber out?

Name: Anonymous 2012-01-22 14:23

>>134
I can now see why I'm even having to argue with you with something that should be obvious. You can't read. Of course that's not an expression. "Used as an expression" means:

if (foo);

There. I used it as an expression.

Also, int foo; is an external definition, not just a declaration. Just in case you didn't know.

Name: Anonymous 2012-01-22 14:25

>>137
But what you cited related to an expression. Having something like

int foo;

or even

extern int foo;

isn't an expression. So now, let's stay on topic you mental midget.

Name: Anonymous 2012-01-22 14:29

>Also, int foo; is an external definition,

This is an external variable. And again, this variable has scope, duration, and linkage.

Name: Anonymous 2012-01-22 14:44

>>138
No, you misunderstood. It's saying that if the variable is used as an expression, it must be defined. Otherwise, it need not be. However, we're going slightly off-topic. The original argument, that all global variables have static duration, still stands. I don't count variables that have no definition.

>>139
What I'm getting at is that it does have a definition.

Name: Anonymous 2012-01-22 15:05

>>140
something like

int foo;

has a definition.

The original argument, that all global variables have static duration

This is still incorrect you idiot. Of course the only way you would know this is if you would have written some actual C code instead of arguing with me.

Name: Anonymous 2012-01-22 15:09

>>141
Why don't you point me to somewhere in the standard that says otherwise.

Name: Anonymous 2012-01-22 15:15

>>142
Under section 6.2.2

"If the declaration of a file scope identifier for an object or a function contains the storage-class specifier static, the identifiere has internal linkage."

Now you annoying stupid shit, the point is, using static modifies the global variable in such a way that is now has internal linkage. In other words, there passage in no way shape or form implies that global variables have static duration.

Name: Anonymous 2012-01-22 15:17

>>142
The passage says it and my conformant C compiler seems to verify it. The fact that you misunderstood the passage just means that you're a mental midget.

Name: Anonymous 2012-01-22 15:19

>>143
Holy fuck, the storage-class specifier static has nothing to with static duration.

Name: Anonymous 2012-01-22 15:21

>>145
Yes it does. Read the definition of static again you fucking moron.

Name: Anonymous 2012-01-22 15:25

>>146
Better yet, let me cite it for your stupid ass..

Under section 6.2.4

"An object whose identifier is declared with external or internal linkate, or with the storage-class specififer static has static storage duration. Its lifetime is the entire exeuction of the program and its stored value is initialized only once, prior to the program startup."

In other words, 'static storage duration' is a result of using the 'static' keyword you fucking idiot.

Name: Anonymous 2012-01-22 15:25

>>146
An object has a storage duration that determines its lifetime. There are three storage durations: static, automatic, and allocated. An object whose identifier is declared with external or internal linkage, or with the storage-class specifier static has static storage duration. Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup.

I don't know they emphasized that the storage-class specifier static here, but if you use your common sense, a global variable with internal linkage was obviously declared with the static specifier.

Name: Anonymous 2012-01-22 15:28

>>148
Becaue they know more than you.

Name: Anonymous 2012-01-22 15:28

>>147
I don't know why they emphasized that, but how about you read that quotation again. If it has external or internal linkage, it has static duration. so it isn't only if you use the static specifier.

Name: Anonymous 2012-01-22 15:29

>>150
Huh? static storage duration is a result of using the static keyword. What part of this doesn't your retarded ass get?

Name: Anonymous 2012-01-22 15:31

>>150
Because the point is fucking stupid shit that properties of the variable change once you remove the 'static' keyword. This is why are emphazing what they are. Holy shit you're stupid.

Name: Anonymous 2012-01-22 15:31

>>151
An object whose identifier is declared with external or internal linkage, or with the storage-class specifier static has static storage duration.

THIS CAN ONLY BE A GLOBAL VARIABLE HURR DURR

Name: Anonymous 2012-01-22 15:34

Actually, if you look at the start of the passage, they clearly state "An object has a storage duration that determines its lifetime"

This is before they talk about 'static'. This implies that a variable, by default, wether it be local or global, doesn't have static storage duration.

Name: Anonymous 2012-01-22 15:36

>>154
No, it implies that static duration isn't the only type of duration in general. However, in the case of global variables, it always has static duration. God damn, just read over what I quoted.

Name: Anonymous 2012-01-22 15:38

>>155
Read the entire passage you fucking idiot. Nowhere does it imply it. And the fact that you think it does just tells me that you are a fucking idiot. Again, the passages doesn't imply it, and again, my compiler seems to verify it.

Name: Anonymous 2012-01-22 15:39

>>155
The 'static' keyword modifies the variable. If there is no 'static', there is no modification. This applies to any variables. Even globals. Again, read it again you fucking moron.

Name: Anonymous 2012-01-22 15:45

>>156
What do you mean your compiler verifies it?

Please tell me you know that static duration and the static specifier are two different things? The latter means that the variable has internal linkage, and is one of the conditions for a variable to have static duration, mutually exclusive. The other is external linkage. Using deduction, it becomes clear that all global variables have static duration, because global variables cannot have no linkage, which is the only other type of linkage.

Now please give your responses a second thought before clicking reply, you inept fuck.

>>157
...

Name: Anonymous 2012-01-22 15:51

>>158
The latter means that the variable has internal linkage, and is one of the conditions for a variable to have static duration, mutually exclusive.

Yes.

The other is external linkage.

Yes

Using deduction, it becomes clear that all global variables have static duration, because global variables cannot have no linkage, which is the only other type of linkage.

No. Global variables can have linkage you moron.

>Now please give your responses a second thought before clicking reply, you inept fuck.

You're the minimum wage toilet scrubber. Not me.

Name: Anonymous 2012-01-22 15:59

>>159
No. Global variables can have linkage you moron.
I said they cannot have no linkage. The only variables with no linkage are those declared at block scope or function prototype scope. That isn't to say that variables with block scope can't have external linkage (they can if you use the extern storage-class specifier). Check out the standard:

The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier extern.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List