the statement
>
printf("%d %d");
>
will print the 1st 2nd initialized variables(if present)
how is tht possible
No, it won't.
It will print whatever rubbish happens to be found by printf on
the stack where it expects two ints. Your implementation may
just happen to keep two previously initialised variables there.
Mine has proper rubbish.
Some would also argue it won't necessarily print a thing, as you
don't show you printed a terminating newline anywhere. ;)
It's undefined what happens really, as you should have supplied
two ints.
> the statement
>>
>printf("%d %d");
>>
>will print the 1st 2nd initialized variables(if present)
>how is tht possible
>
No, it won't.
>
It will print whatever rubbish happens to be found by printf on
the stack where it expects two ints. Your implementation may
just happen to keep two previously initialised variables there.
Mine has proper rubbish.
What stack? It has undefined behaviour.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
>> the statement
>>>
>>printf("%d %d");
>>>
>>will print the 1st 2nd initialized variables(if present)
>>how is tht possible
>No, it won't.
>>
>It will print whatever rubbish happens to be found by printf on
>the stack where it expects two ints. Your implementation may
>just happen to keep two previously initialised variables there.
>Mine has proper rubbish.
>
What stack? It has undefined behaviour.
Was that a necessary comment?
I even said it was undefined -- in the bit that you snipped.
And the reason OP was getting the behaviour he was had to do
with his particular implementation so that was the reply he got,
seeing as this was what he was talking about. His question was
"how is that possible". I gave one possible theory.
I know you've all been busy with Jacob and stack recently but I
wasn't expecting it to spill over all of the group...
>> the statement
>>>
>>printf("%d %d");
>>>
>>will print the 1st 2nd initialized variables(if present)
>>how is tht possible
>>
>No, it won't.
>>
>It will print whatever rubbish happens to be found by printf on
>the stack where it expects two ints. Your implementation may
>just happen to keep two previously initialised variables there.
>Mine has proper rubbish.
>
What stack? It has undefined behaviour.
Probably the stack that his environment uses I would dare say. The one
the debugger displays. Duh. Whether that stack is used in this case is
another issue, but it was fairly clear what stack he meant.
Vladimir Oka <vladimir....@b topenworld.comw rote:
CBFalconer wrote:
Vladimir Oka wrote:
jt wrote:
the statement
printf("%d %d");
will print the 1st 2nd initialized variables(if present)
how is tht possible
>
No, it won't.
>
It will print whatever rubbish happens to be found
by printf on the stack where it expects two ints.
Actually, it expects two void pointers.
Your
implementation may just happen to keep two previously
initialised variables there. Mine has proper rubbish.
On Mon, 03 Mar 2008 18:35:07 -0800, Peter Nilsson wrote:
Vladimir Oka <vladimir....@b topenworld.comw rote:
>CBFalconer wrote:
Vladimir Oka wrote:
jt wrote:
 the statement
printf("%d %d");
will print the 1st 2nd initialized variables(if present) how is
tht possible
>
No, it won't.
>
It will print whatever rubbish happens to be found by printf on the
stack where it expects two ints.
>
Actually, it expects two void pointers.
I thought the "%d" conversion specifier expects type int. Isn't the
conversion specifier for a void pointer "%p"?
The way I read your comment, you are you saying that something like this
is acceptable?
On Mon, 03 Mar 2008 18:35:07 -0800, Peter Nilsson wrote:
>
>Vladimir Oka <vladimir....@b topenworld.comw rote:
>>CBFalconer wrote:
>Vladimir Oka wrote:
>jt wrote:
> Â the statement
> printf("%d %d");
> will print the 1st 2nd initialized variables(if present) how is
> tht possible
<snip>
>It will print whatever rubbish happens to be found by printf on the
>stack where it expects two ints.
>>
>Actually, it expects two void pointers.
>
I thought the "%d" conversion specifier expects type int. Isn't the
conversion specifier for a void pointer "%p"?
Yes. I believe it's fair to say that Mr Nilsson misread. :)
--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
Vladimir Oka <vladimir....@b topenworld.comw rote:
>CBFalconer wrote:
>>Vladimir Oka wrote:
>>>Your
>>>implementati on may just happen to keep two previously
>>>initialise d variables there. Mine has proper rubbish.
>>What stack? It has undefined behaviour.
>Was that a necessary comment?
>
Was yours?
>
Martin gave the answer the OP needed.
I respectfully disagree.
The OP asked along the lines of "how is it possible that I get
this silly behaviour". I disagree it enhances OP's understanding
of software in general if he gets the answer "it's undefined
behaviour, don't do it (and don't think about it further)." My
reply offered one possible scenario that could lead to undefined
behaviour having the outcome seen by the OP. I believe that is
the reply OP needed.
Not to mention I also pointed out it was undefined, but that was
snipped from CBFalconer's response, making my reply seem incomplete.
In article <zbednbqbvIsjj1 DanZ2dnUVZ8u-dnZ2d@bt.com>,
Vladimir Oka <vladimir.oka@b topenworld.comw rote:
....
>I respectfully disagree.
>
>The OP asked along the lines of "how is it possible that I get
>this silly behaviour". I disagree it enhances OP's understanding
>of software in general if he gets the answer "it's undefined
>behaviour, don't do it (and don't think about it further)." My
>reply offered one possible scenario that could lead to undefined
>behaviour having the outcome seen by the OP. I believe that is
>the reply OP needed.
>
>Not to mention I also pointed out it was undefined, but that was
>snipped from CBFalconer's response, making my reply seem incomplete.
Welcome to CLC.
I think I need to add this to my list of useful CLC-related links:
Comment