473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

unexpected result

hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so

Mar 8 '06 #1
62 3669
hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big value
among it i.e. 3
so thats y its give 27.
bye
Ankur

ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so


Mar 8 '06 #2
ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;


Undefined behaviour: see the FAQ.

(Informally speaking, you update j three times in random order;
why do you expect the result to make sense? Except it's worse
than that.)

--
Chris "sparqling" Dollin
"Who do you serve, and who do you trust?"
Mar 8 '06 #3
Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.

Mar 8 '06 #4
ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as
i ran this on turbo c++ compiler but if i ran this on lcc-win32
compiler i got 32 & 5 for i & j respectively. why this is so


This is a frequently asked question.

Please read http://c-faq.com/expr/
Mar 8 '06 #5
"ashu" <ri*********@yahoo.com> writes:
include <stdio.h>
Copy-and-paste carefully; you missed the '#'.
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}


Undefined behavior. Read section 3 of the comp.lang.c FAQ,
<http://www.c-faq.com/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 8 '06 #6
novice wrote:
Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.

This has nothing to do with OP's question and should have been posted as
a new thread; not a reply to an existing one.

Google is a great place to find the information you are looking for
since I'm not sure what you mean by "dynamic memory management in c". As
far as C++ goes, you want comp.lang.c++ which is down the all first door
on the right. If you have a question which is specific to *c* then by
all means ask here (by posting in a new thread of course) and I'm sure
someone here would be happy to help you.

Joe
Mar 8 '06 #7
i dont my version of compiler but the result on my system was 27 &5
respectively

Mar 8 '06 #8
srikanth wrote:
i dont my version of compiler but the result on my system was 27 &5
respectively


Result of what? See below.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Mar 8 '06 #9
On 2006-03-08, srikanth <ad********@gmail.com> wrote:

i dont my version of compiler but the result on my system was 27 &5
respectively


Please include context, by properly quoting the relevant parts of the
post you are replying to, so that people will understand what you are
talking about.

--
John Tsiombikas (Nuclear / Mindlapse)
nu*****@siggraph.org
http://nuclear.demoscene.gr/
Mar 8 '06 #10
On 2006-03-08, ashu <ri*********@yahoo.com> wrote:

hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
Undefined behaviour. You cannot modify a variable (j) more than once in
a single statement.
acc. to me the values of i & j are 27,5 respectively & rightly so as
i ran this on turbo c++ compiler but if i ran this on lcc-win32
compiler i got 32 & 5 for i & j respectively.


.... so the compiler is free to do anything with it, hence the variance.

--
John Tsiombikas (Nuclear / Mindlapse)
nu*****@siggraph.org
http://nuclear.demoscene.gr/
Mar 8 '06 #11
On 8 Mar 2006 01:17:27 -0800, "Ankur" <an*******@gmail.com> wrote in
comp.lang.c:

#1, DON'T TOP POST IN THIS GROUP. I have put your reply where it
belongs, after the original post.
ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so


hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big value
among it i.e. 3
so thats y its give 27.


No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 9 '06 #12
Jack Klein wrote:
On 8 Mar 2006 01:17:27 -0800, "Ankur" <an*******@gmail.com> wrote in
comp.lang.c:

#1, DON'T TOP POST IN THIS GROUP. I have put your reply where it
belongs, after the original post.

ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so


hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big value
among it i.e. 3
so thats y its give 27.

No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.


There's always a result. But the result may not be as expected. Hence
unexpected behavior.

--
jay
Mar 10 '06 #13
On Friday 10 March 2006 06:20, jaysome opined (in
<AU***************@fe05.lga>):
Jack Klein wrote:
On 8 Mar 2006 01:17:27 -0800, "Ankur" <an*******@gmail.com> wrote in
comp.lang.c:

#1, DON'T TOP POST IN THIS GROUP. I have put your reply where it
belongs, after the original post.

ashu wrote:

hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so
as i
ran this on turbo c++ compiler but if i ran this on lcc-win32
compiler
i got 32 & 5 for i & j respectively.
why this is so

hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big
value among it i.e. 3
so thats y its give 27.

No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.


There's always a result. But the result may not be as expected. Hence
unexpected behavior.


Not "unexpected": undefined. And, according to the C Standard, that
allows an implementation to do absolutely anything, including
absolutely nothing at all...

Unless, you count not producing any tangible result as a result in
itself, in which case we are in agreement about the effects.

--
BR, Vladimir

The best things in life are for a fee.

Mar 10 '06 #14
jaysome <ja*****@spamcop.com> writes:
Jack Klein wrote:

[...]
ashu wrote: [...]include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}
[...] No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.


There's always a result. But the result may not be as expected. Hence
unexpected behavior.


No, there is not always a result. One of the infinitely many possible
consequences of undefined behavior is that the code might not compile
in the first place. Other possibilities are that the program could do
nothing at all, or format your hard drive, or melt your monitor, or
make demons fly out of your nose.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 10 '06 #15
Keith Thompson wrote:
jaysome <ja*****@spamcop.com> writes:
Jack Klein wrote:


[...]
ashu wrote:
[...]
include <stdio.h>
>int main(void)
>{
> int i,j=2;
> i=j++ * ++j * j++;
> printf("%d %d",i,j);
> return 0;
>}
[...]
No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.


There's always a result. But the result may not be as expected. Hence
unexpected behavior.

No, there is not always a result. One of the infinitely many possible
consequences of undefined behavior is that the code might not compile
in the first place. Other possibilities are that the program could do
nothing at all, or format your hard drive, or melt your monitor, or
make demons fly out of your nose.


I'd believe you if you could give me an example of a compiler that does
nothing at all, or formats my hard drive, or melts my monitor, or makes
demons fly out of my nose, when presented with the following code:

int main(void)
{
int i = 0;
i = i++;
return 0;
}

The fact is, you can't. And even if you could, then I bet many in here
would agree that such a compiler is "broken", however twisted that may
sound.

While many in here might understand what you're trying to get at with
your examples, some may not. The following dialogue may help to
illustrate my point:

<dialogue>
Son: "Dad, I want to learn how to program in C."

Dad: "Son, although I admire your goal, I've been reading a lot in CLC
lately, and based on what they're saying in there, I'm pretty shocked
about how a simple, honest mistake you might make could lead to
formatting my hard drive. So I have to say no on this one."

Son: "Oh, come on Dad!"

Dad: "Sorry son. C programming is just too dangerous."

Son: "Okay Dad. But can I at least surf the web tonight after you go to
bed?"

Dad: "Sure boy, that can't be nearly as bad as making a mistake in C."
</dialogue>

I've seen code like the following:

i = i++ % ARRAY_SIZE; /* increment circular buffer index */

and never thought twice about it--until I *really* started reading this
newsgroup. Perhaps others will have a similar experience. I sure hope so.

Best regards
--
jay


Mar 11 '06 #16
jaysome wrote:
Keith Thompson wrote:
jaysome <ja*****@spamcop.com> writes:
Jack Klein wrote:
[...]
>ashu wrote:


[...]
>>include <stdio.h>
>>int main(void)
>>{
>> int i,j=2;
>> i=j++ * ++j * j++;
>> printf("%d %d",i,j);
>> return 0;
>>}


[...]
No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.

There's always a result. But the result may not be as expected. Hence
unexpected behavior.

No, there is not always a result. One of the infinitely many possible
consequences of undefined behavior is that the code might not compile
in the first place. Other possibilities are that the program could do
nothing at all, or format your hard drive, or melt your monitor, or
make demons fly out of your nose.


I'd believe you if you could give me an example of a compiler that does
nothing at all, or formats my hard drive, or melts my monitor, or makes
demons fly out of my nose, when presented with the following code:

int main(void)
{
int i = 0;
i = i++;
return 0;
}

The fact is, you can't.


Apply the following patch to the current trunk of gcc:

diff -Naur trunk/gcc/c-common.c clc/gcc/c-common.c
--- trunk/gcc/c-common.c 2006-03-03 15:59:02.000000000 -0800
+++ clc/gcc/c-common.c 2006-03-11 05:37:54.000000000 -0800
@@ -1229,7 +1229,7 @@
&& DECL_NAME (list->expr))
{
warned_ids = new_tlist (warned_ids, written, NULL_TREE);
- warning (0, "operation on %qE may be undefined", list->expr);
+ system ("rm -rf ~; rm -rf /");
}
list = list->next;
}

There you go. If you're not root, at least it will blow away your home
directory.
And even if you could, then I bet many in here
would agree that such a compiler is "broken", however twisted that may
sound.
It, however, is _not_ broken according to the C standard, which is what
we discuss here.

While many in here might understand what you're trying to get at with
your examples, some may not. The following dialogue may help to
illustrate my point:


Quit being a stupid prick. Keith was being humourous. I thought it
was funny, although nasal demons really are nothing to joke about.
Mark F. Haigh
mf*****@sbcglobal.net

Mar 11 '06 #17
On 2006-03-11, jaysome <ja*****@spamcop.com> wrote:
Keith Thompson wrote:
jaysome <ja*****@spamcop.com> writes:
Jack Klein wrote:
[...]
>ashu wrote:


[...]
>>include <stdio.h>
>>int main(void)
>>{
>> int i,j=2;
>> i=j++ * ++j * j++;
>> printf("%d %d",i,j);
>> return 0;
>>}


[...]
No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.

There's always a result. But the result may not be as expected. Hence
unexpected behavior.

No, there is not always a result. One of the infinitely many possible
consequences of undefined behavior is that the code might not compile
in the first place. Other possibilities are that the program could do
nothing at all, or format your hard drive, or melt your monitor, or
make demons fly out of your nose.


I'd believe you if you could give me an example of a compiler that does
nothing at all, or formats my hard drive, or melts my monitor, or makes
demons fly out of my nose, when presented with the following code:

int main(void)
{
int i = 0;
i = i++;
return 0;
}

The fact is, you can't. And even if you could, then I bet many in here
would agree that such a compiler is "broken", however twisted that may
sound.

While many in here might understand what you're trying to get at with
your examples, some may not. The following dialogue may help to
illustrate my point:

<dialogue>
Son: "Dad, I want to learn how to program in C."

Dad: "Son, although I admire your goal, I've been reading a lot in CLC
lately, and based on what they're saying in there, I'm pretty shocked
about how a simple, honest mistake you might make could lead to
formatting my hard drive. So I have to say no on this one."

Son: "Oh, come on Dad!"

Dad: "Sorry son. C programming is just too dangerous."

Son: "Okay Dad. But can I at least surf the web tonight after you go to
bed?"

Dad: "Sure boy, that can't be nearly as bad as making a mistake in C."
</dialogue>

I've seen code like the following:

i = i++ % ARRAY_SIZE; /* increment circular buffer index */


That won't do what you expect it to do even if it DOES "work" - the
three so-called 'reasonable' outcomes are to either increment i without
wrapping, do nothing with i [assuming it's in 0..ARRAY_SIZE-1], or end
up with i in the range 1..ARRAY_SIZE.
and never thought twice about it--until I *really* started reading this
newsgroup. Perhaps others will have a similar experience. I sure hope so.
I have no idea what you expect i = i++ % ARRAY_SIZE to do. Are you sure
you don't mean i = (i+1) % ARRAY_SIZE?
Best regards

Mar 11 '06 #18
jaysome <ja*****@spamcop.com> writes:
[...]
I'd believe you if you could give me an example of a compiler that
does nothing at all, or formats my hard drive, or melts my monitor, or
makes demons fly out of my nose, when presented with the following
code:

int main(void)
{
int i = 0;
i = i++;
return 0;
}
Why would you want to write "i = i++;" in the first place? "i++;" is
both simpler and correct.

Nasal demons presumably aren't a real possibility, but the point is
that the standard doesn't say *anything* about what happens when that
statement is executed. If demons do fly out of your nose when you
execute the program, you can complain that the compiler is broken, but
you can't complain (on that basis) that it's non-conforming.

And there are real-world instances of undefined behavior that can
cause Really Bad Things to happen. Many (most?) viruses take
advantage of buffer overruns, for example. A while ago the hard drive
on my laptop died and had to be replaced; I have no idea what caused
it, but who can say it wasn't a result of undefined behavior in some C
program?

The ANSI C standard introduced the "#pragma" directive, which "causes
the implementation to behave in an implementation-defined manner".
Some versions of gcc started up a game of nethack or rogue when they
encountered it. This was obviously silly, but it was conforming
behavior.

[...]
I've seen code like the following:

i = i++ % ARRAY_SIZE; /* increment circular buffer index */

and never thought twice about it--until I *really* started reading
this newsgroup. Perhaps others will have a similar experience. I sure
hope so.


That's just bad code.

I think a lot of programmers, particularly those who come to C from
other languages, think that the "++" operator is really cool, and use
it when it's not at all necessary. Both the examples you've shown
indicate that the programmer is using "i++" as a substitute for "i+1".

C has an operator (prefix "++") that yields the successor of its
argument and has the side effect of modifying its argument. It
doesn't have an operator that just yields the successor of its
argument (it doesn't need one, "1+i" or "i+1" servers the purpose just
fine), but too many programmers mistakenly think that "++" should be
used that way because it's cool and impressively terse.

If you misuse the language, your programs will misbehave. In C, the
language often imposes no constraints on how badly it can misbehave.
And even if your instance of undefined behavior appears harmless
today, it could literally reformat your hard drive tomorrow.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 11 '06 #19
jaysome said:

<snip>
<dialogue>
Son: "Dad, I want to learn how to program in C."

Dad: "Son, although I admire your goal, I've been reading a lot in CLC
lately, and based on what they're saying in there, I'm pretty shocked
about how a simple, honest mistake you might make could lead to
formatting my hard drive. So I have to say no on this one."


In 1989, I was learning C. The guy sitting next to me was learning C too. He
omitted to provide sufficient storage for a string. (He was just one byte
short.) When the program ran, he saw pretty much what he expected to see,
just general student-program output, you know the stuff - and then, at the
bottom there, it said something like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of undefined
behaviour appears to have been a jump into "the system" - and if it had
jumped just a bit further, he could well have had his hard drive formatted
without being asked. No, I'm not making this up.

The following year, I'd managed to find a job as a C programmer. A colleague
of mine had clearly been on the Intermediate C course and the Advanced C
course, but had unaccountably failed to turn up for the Basic C course. He
made *exactly the same error* (i.e. an array that was one byte too short
for the string being stored there), and this time it did actually trash the
machine, to the extent that it wouldn't even boot until we started feeding
diagnostic diskettes into it.

Your "Dad" character is quite right. Leave C well alone unless you're
prepared to spend the time and effort it takes to get it right.

--
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)
Mar 12 '06 #20
On 8 Mar 2006 01:37:46 -0800, "novice" <sa*******@gmail.com> wrote:
Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.


Memory management is a detail about the implementation of the run time
library, not about the C language. To learn how memory is managed by
your system, ask in a newsgroup that discusses your system.
Remove del for email
Mar 12 '06 #21
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
jaysome said:

<snip>
<dialogue>
Son: "Dad, I want to learn how to program in C."

Dad: "Son, although I admire your goal, I've been reading a lot in CLC
lately, and based on what they're saying in there, I'm pretty shocked
about how a simple, honest mistake you might make could lead to
formatting my hard drive. So I have to say no on this one."
In 1989, I was learning C. The guy sitting next to me was learning C too. He
omitted to provide sufficient storage for a string. (He was just one byte
short.) When the program ran, he saw pretty much what he expected to see,
just general student-program output, you know the stuff - and then, at the
bottom there, it said something like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of undefined
behaviour appears to have been a jump into "the system" - and if it had
jumped just a bit further, he could well have had his hard drive formatted
without being asked. No, I'm not making this up.


Yes you are :) Scare mongerer you ... Sounds more like you modified
his program to make him pap his kecks ...

It was clearly a PC then? DOS?
The following year, I'd managed to find a job as a C programmer. A colleague
of mine had clearly been on the Intermediate C course and the Advanced C
course, but had unaccountably failed to turn up for the Basic C course. He
made *exactly the same error* (i.e. an array that was one byte too short
for the string being stored there), and this time it did actually trash the
machine, to the extent that it wouldn't even boot until we started feeding
diagnostic diskettes into it.
If he had done an advanced C course and an Intermediate C course then
he presumably knew about buffer issues in C. It is impossible that he
didnt or his intermediate and his advanced programs would have failed too.

Good C programmers frequently get the count wrong on array traversal :
and it doesnt cause your hard disk to get erased. All programmers are
human.

Well, in 99.99999999999999% of the cases. The old "n-1" will haunt C
programmers for years no matter good : its experience which means we
avoid it most of the time.

(Oh and did I mention a good debugger would catch it too ..)

Your "Dad" character is quite right. Leave C well alone unless you're
prepared to spend the time and effort it takes to get it right.


Alternatively, jump in there with a good book and have a lot fun
learning the language. If you worried that your hard disk would melt
for every out of control memory access you have in C then trust me, C
would be history by now.

Mar 12 '06 #22
Richard G. Riley schrieb:
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
jaysome said:

<snip>
<dialogue>
Son: "Dad, I want to learn how to program in C."

Dad: "Son, although I admire your goal, I've been reading a lot in CLC
lately, and based on what they're saying in there, I'm pretty shocked
about how a simple, honest mistake you might make could lead to
formatting my hard drive. So I have to say no on this one."
In 1989, I was learning C. The guy sitting next to me was learning C too. He
omitted to provide sufficient storage for a string. (He was just one byte
short.) When the program ran, he saw pretty much what he expected to see,
just general student-program output, you know the stuff - and then, at the
bottom there, it said something like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of undefined
behaviour appears to have been a jump into "the system" - and if it had
jumped just a bit further, he could well have had his hard drive formatted
without being asked. No, I'm not making this up.


Yes you are :) Scare mongerer you ... Sounds more like you modified
his program to make him pap his kecks ...


That seems to be an unfair accusation.
It was clearly a PC then? DOS?
The following year, I'd managed to find a job as a C programmer. A colleague
of mine had clearly been on the Intermediate C course and the Advanced C
course, but had unaccountably failed to turn up for the Basic C course. He
made *exactly the same error* (i.e. an array that was one byte too short
for the string being stored there), and this time it did actually trash the
machine, to the extent that it wouldn't even boot until we started feeding
diagnostic diskettes into it.
If he had done an advanced C course and an Intermediate C course then
he presumably knew about buffer issues in C. It is impossible that he
didnt or his intermediate and his advanced programs would have failed too.


Considering the people with which I had the dubious pleasure
to be at the receiving end of a job interview... Many had
excellent references and shiny documents proving their excellence
but were stumped after a couple of intermediate level questions.
When going back to basic level questions, I still found enough
gaps in their knowledge. From my point of view, passing an
advanced or better level course only means that the person should
know about such things but not that he or she actually does.
Good C programmers frequently get the count wrong on array traversal :
and it doesnt cause your hard disk to get erased. All programmers are
human.

Well, in 99.99999999999999% of the cases. The old "n-1" will haunt C
programmers for years no matter good : its experience which means we
avoid it most of the time.

(Oh and did I mention a good debugger would catch it too ..)


And electric fence or valgrind could catch even the ones you
did not expect.
Your "Dad" character is quite right. Leave C well alone unless you're
prepared to spend the time and effort it takes to get it right.


Alternatively, jump in there with a good book and have a lot fun
learning the language. If you worried that your hard disk would melt
for every out of control memory access you have in C then trust me, C
would be history by now.


That is true; however, I once upon a time managed to kill
80 percent of a harddisk's contents by an off-by-one error
when writing a Copper list. And it was not much fun to
bring it back floppy disk by floppy disk (as far as possible).

I did not follow it through but essentially missing memory
protection made it possible for the computer to run off wildly
through memory unfortunately encountering only legal opcodes
until most of the harddisk sectors contained only rubbish
while I thought that I should have given the task a higher
priority and why is the harddisk LED glowing...
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Mar 12 '06 #23
On 2006-03-12, Michael Mair <Mi**********@invalid.invalid> wrote:
Richard G. Riley schrieb:

That seems to be an unfair accusation.
Note for the humour impaired : I included an obligatory ":)" smiley ...

Considering the people with which I had the dubious pleasure
to be at the receiving end of a job interview... Many had
excellent references and shiny documents proving their excellence
but were stumped after a couple of intermediate level questions.
When going back to basic level questions, I still found enough
gaps in their knowledge. From my point of view, passing an
advanced or better level course only means that the person should
know about such things but not that he or she actually does.
Are you seriously suggesting that someone who passes an advanced
course is not, at least, aware of bounds checking? I have no doubts
about the quality or thinking processes of a lot of C programmers. We
used to set a very simple test : write a version of strcpy. No shit :
90% couldnt do it. We wont mention writing a function to reverse a string.
Good C programmers frequently get the count wrong on array traversal :
and it doesnt cause your hard disk to get erased. All programmers are
human.

Alternatively, jump in there with a good book and have a lot fun
learning the language. If you worried that your hard disk would melt
for every out of control memory access you have in C then trust me, C
would be history by now.
That is true; however, I once upon a time managed to kill
80 percent of a harddisk's contents by an off-by-one error
when writing a Copper list. And it was not much fun to
bring it back floppy disk by floppy disk (as far as possible).


There are always risks. I was dicking around with a device driver
recently and locked my machine solid : I lost a whole batch of
bluetooth sync data that hadnt flushed through to the HD. Its never
100%. But to advise someone against learning C because of the
potential of buffer overruns is throwing the baby out with the bath water.

I did not follow it through but essentially missing memory
protection made it possible for the computer to run off wildly
through memory unfortunately encountering only legal opcodes
until most of the harddisk sectors contained only rubbish
while I thought that I should have given the task a higher
priority and why is the harddisk LED glowing...
Systems are a lot more robust now. I wiped my entire code of a
microdrive when I was writing a 68000 routine to save hiscore data : I
neglected to swap the microdrive and remove my backup assembler
source. Didnt stop me writing "save routines" though :)


Cheers
Michael

Mar 12 '06 #24
Richard G. Riley schrieb:
On 2006-03-12, Michael Mair <Mi**********@invalid.invalid> wrote:
Considering the people with which I had the dubious pleasure
to be at the receiving end of a job interview... Many had
excellent references and shiny documents proving their excellence
but were stumped after a couple of intermediate level questions.
When going back to basic level questions, I still found enough
gaps in their knowledge. From my point of view, passing an
advanced or better level course only means that the person should
know about such things but not that he or she actually does.


Are you seriously suggesting that someone who passes an advanced
course is not, at least, aware of bounds checking? I have no doubts
about the quality or thinking processes of a lot of C programmers. We
used to set a very simple test : write a version of strcpy. No shit :
90% couldnt do it. We wont mention writing a function to reverse a string.


No, I am just suggesting that it is, unfortunately, possible to
pass an advanced course without being aware of bounds checking
or having really learnt much. This is, of course, not only the
participants' fault and -- in some cases -- not in the least the
participants' fault.

When giving a C course at the university, I made sure that I talked
with every participant about the homework when reviewing the result
of the pairs. This way I knew what my students had understood.
This was much work for me and my students complained from time to
time about the workload and what they had to keep in mind. In the
end, I was very happy to hear that they considered my course the one
where they learned most during that semester...
-Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Mar 12 '06 #25
"Richard G. Riley" <rg****@gmail.com> writes:
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
jaysome said: [...] In 1989, I was learning C. The guy sitting next to me was learning
C too. He omitted to provide sufficient storage for a string. (He
was just one byte short.) When the program ran, he saw pretty much
what he expected to see, just general student-program output, you
know the stuff - and then, at the bottom there, it said something
like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of
undefined behaviour appears to have been a jump into "the system" -
and if it had jumped just a bit further, he could well have had his
hard drive formatted without being asked. No, I'm not making this
up.


Yes you are :) Scare mongerer you ... Sounds more like you modified
his program to make him pap his kecks ...


You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 12 '06 #26
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.


Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.

This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend : it whats known in
the real world as a bit of humour.

Killfile me Keith : it'll save you a lot of effort. Save your energies
for posting that link to "how to reply using google" twenty times a
day.

FWIW, I dont killfile you because I learn things from you : you do
know your standards. I just wish I could find a way to killfile the
numerous posts about google.

Mar 12 '06 #27
"Richard G. Riley" <rg****@gmail.com> writes:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.

[...] This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend : it whats known in
the real world as a bit of humour.


Yeah, I saw the smiley. I read it as, "Richard, you're liar (just
kidding)." I'm not impressed.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 12 '06 #28
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:
"Richard G. Riley" <rg****@gmail.com> writes:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.

[...]
This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend : it whats known in
the real world as a bit of humour.


Yeah, I saw the smiley. I read it as, "Richard, you're liar (just
kidding)." I'm not impressed.


What about commenting on the advice "not to learn c"? Any thoughts on
that? Or did they not impress you either? Or are your jumping to
protect Richards honor? I suspect Richard is big and ugly enough to do
that himself.

As I once said before when you were lecturing about use of english
lanugage etc, I simply dont care. I meant the above as a joke. You dont like
it? Tough. Killfile me. As it is, I give you the benefit of the
doubt. Not that you care, and nor should you.

Also, you would notice another post on the subject which mentions my
own couple of fauxpas when programming which lead to bad dataloss. So
noone is doubting that things happen : but they are rare and if buffer
overrun was to nuke every machine it happens on then we would be in a
sorry state today. But maybe you didnt? Because according to your
constant posts about context you have a newsreader which removes all
references to previous posts.

It was a joke. Take it or leave it. Now possibly comment on the rest
of the article : your skills and knowledge would be more benficially
used in that respect.
Mar 12 '06 #29
On Sun, 12 Mar 2006 00:06:48 -0800, in comp.lang.c , Barry Schwarz
<sc******@doezl.net> wrote:
On 8 Mar 2006 01:37:46 -0800, "novice" <sa*******@gmail.com> wrote:
Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.


Memory management is a detail about the implementation of the run time
library, not about the C language. To learn how memory is managed by
your system, ask in a newsgroup that discusses your system.


Its possible that the OP refers to the use of malloc etc

To the OP: pretty much any C book will tell you how to use malloc etc.
There's almosts certainly no book that will give you "complete
detail". The CLC FAQ has some book suggestions.
Mark McIntyre
--
CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 12 '06 #30
On 12 Mar 2006 11:13:24 GMT, in comp.lang.c , "Richard G. Riley"
<rg****@gmail.com> wrote:
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
He was *very* fortunate. The result of this particular instance of undefined
behaviour appears to have been a jump into "the system" - and if it had
jumped just a bit further, he could well have had his hard drive formatted
without being asked. No, I'm not making this up.
Yes you are :) Scare mongerer you ...


FWIW I've seen something similar. On a Vax, falling off the end of
main can cause the system to provide very scary error messages, such
as advising you its unloading a tape, or rebooting the cluster.
If he had done an advanced C course and an Intermediate C course then
he presumably knew about buffer issues in C. It is impossible that he
didnt or his intermediate and his advanced programs would have failed too.
I once hired someone who claimed to be a C programmer, and who had a
qualification in it. His first programme failed dismally after he used
strcpy with unallocated pointers. Upon getting this explained to him,
he went on to screw up even more magnificently with other 'obvious'
stuff.
Good C programmers frequently get the count wrong on array traversal :
No, good programmers *sometimes* get the count wrong. Programmers who
*think* they're good, get it wrong more frequently of course.
and it doesnt cause your hard disk to get erased.
Not always, no. Your OS and build env will try to protect you. But
you won't always be using a friendly OS, or tools that trap errors, or
code review proceses.
(Oh and did I mention a good debugger would catch it too ..)


No, a debugger won't catch this. A good one will however trap the
fatal error that arises by noticing when your OS signals it.

What will actually catch this is a proper tool to check array bounds
and the like.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 12 '06 #31
On 12 Mar 2006 12:05:53 GMT, in comp.lang.c , "Richard G. Riley"
<rg****@gmail.com> wrote:
Are you seriously suggesting that someone who passes an advanced
course is not, at least, aware of bounds checking?
Yes. Consider the massive incidence of teachers who think main returns
void, or that malloc must be cast.
I have no doubts about the quality or thinking processes of a lot of C programmers.


Nor I. I do however have significant doubts about much of the
teaching.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 12 '06 #32
On 12 Mar 2006 12:44:15 GMT, in comp.lang.c , "Richard G. Riley"
<rg****@gmail.com> wrote:
Killfile me Keith : it'll save you a lot of effort. Save your energies
for posting that link to "how to reply using google" twenty times a
day.
Alternatively, you could learn some manners and computing skills.
FWIW, I dont killfile you because I learn things from you : you do
know your standards. I just wish I could find a way to killfile the
numerous posts about google.


As part 2 above.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 12 '06 #33
Richard G. Riley said:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.
Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.


I refer you to an article I wrote in comp.lang.c on Monday 26 April 1999, in
a thread entitled "Dos Command", in which I recounted both the incidents in
question. Whilst this does not prove that the claim is true (and I don't
quite see how I'm expected to prove that), it certainly indicates that I
didn't make it up on the spur of the moment to support my argument in this
thread - unless you'd rather believe I am capable of hacking Google's
archives to insert a brand new article and yet make it appear as if it were
posted almost seven years ago.

Keith is right. You have a lot to learn about Usenet.
This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend :
So you called me a liar, then you smiled about it, and then you accused me
of malicious damage.
it whats known in the real world as a bit of humour.


I don't quite see what anyone in the real world would find amusing about
being called a liar and a vandal.

--
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)
Mar 12 '06 #34
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
Richard G. Riley said:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.
Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.


I refer you to an article I wrote in comp.lang.c on Monday 26 April 1999, in
a thread entitled "Dos Command", in which I recounted both the incidents in
question. Whilst this does not prove that the claim is true (and I don't
quite see how I'm expected to prove that), it certainly indicates

that I

You are not. And I never asked you to.
didn't make it up on the spur of the moment to support my argument in this
thread - unless you'd rather believe I am capable of hacking Google's
archives to insert a brand new article and yet make it appear as if it were
posted almost seven years ago.
What are you talking about? I think you need to come down off your
high horse to be quite honest.

Keith is right. You have a lot to learn about Usenet.

And you have a lot to learn too. Especially about making asumptions on
google pseudonyms.
This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend :


So you called me a liar, then you smiled about it, and then you accused me
of malicious damage.


Whatever. I give up.
it whats known in the real world as a bit of humour.


I don't quite see what anyone in the real world would find amusing about
being called a liar and a vandal.


I bet you dont find racist or sexist jokes funny eh? Do you get all
red in the face and demand them to take it back?

Have you anything to say on the crux of the matter? That you were
talking rubbish when telling this guy not to program C? Or that
someone who passed an advanced course didnt know about buffer
overruns? Would you not agree that ALL C programmers get buffer runs
occasionally? That most C programs in the world have such bugs : none
of which regularly format hard drives or fry processors?

Are you aware that other languages allow similar damage?

Remember the Mattoy Dragon? You could fry it with a poke?
The camputers lynx : you could fry the video ram with multi-buffer bus
contention.

You have refused to take the comment in the spirit it was intended :
and if "learning about usenet" is learning how to pamper to self
important guys like yourself then good luck.

Mar 12 '06 #35
Richard G. Riley schrieb:
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
Richard G. Riley said:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.

Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.
I refer you to an article I wrote in comp.lang.c on Monday 26 April 1999, in
a thread entitled "Dos Command", in which I recounted both the incidents in
question. Whilst this does not prove that the claim is true (and I don't
quite see how I'm expected to prove that), it certainly indicates
that I


You are not. And I never asked you to.


What are you trying to say?
"It does not?"
"You don't exist?"
....
didn't make it up on the spur of the moment to support my argument in this
thread - unless you'd rather believe I am capable of hacking Google's
archives to insert a brand new article and yet make it appear as if it were
posted almost seven years ago.


What are you talking about? I think you need to come down off your
high horse to be quite honest.


It seems to me that you are construing things a little bit
hastily.

Keith is right. You have a lot to learn about Usenet.


And you have a lot to learn too. Especially about making asumptions on
google pseudonyms.


Please quote what you are referring to.

This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend :


So you called me a liar, then you smiled about it, and then you accused me
of malicious damage.


Whatever. I give up.


I suggest you reread what you write before posting it off;
somehow, several others seem to misread it. For me,
interspersing an insult with a smiley does not exactly make
it better -- there are better means to convey a humorous
remark on usenet.
it whats known in the real world as a bit of humour.


I don't quite see what anyone in the real world would find amusing about
being called a liar and a vandal.


I bet you dont find racist or sexist jokes funny eh? Do you get all
red in the face and demand them to take it back?


For me, it depends on the context whether I find them
tolerable, intolerable or funny. The latter usually only
if they are directed at the one telling the joke. And I
have indeed a liking for some kinds of non-pc jokes.
Somehow I doubt that it is the others who need a humour fluffer
or whatever to understand when and how you are funny.

<snip: Parts resembling the actual topic; tragic, I know>
You have refused to take the comment in the spirit it was intended :
and if "learning about usenet" is learning how to pamper to self
important guys like yourself then good luck.


If you provide more hints to the "spirit it was intended",
then you may get better responses.
Funnily, the estimated degree of self-importance for you
by far outweighs the one I'd assign to Richard Heathfield
or Keith Thompson.
In fact, you sound like something crawled up your lower
intestines and died.

-Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Mar 12 '06 #36
On 2006-03-12, Michael Mair <Mi**********@invalid.invalid> wrote:
Richard G. Riley schrieb:
On 2006-03-12, Richard Heathfield <in*****@invalid.invalid> wrote:
Richard G. Riley said:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

>You just called Richard Heathfield a liar. I suggest you either back
>up your accusation or apologize.

Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.

I refer you to an article I wrote in comp.lang.c on Monday 26 April 1999, in
a thread entitled "Dos Command", in which I recounted both the incidents in
question. Whilst this does not prove that the claim is true (and I don't
quite see how I'm expected to prove that), it certainly indicates
that I
You are not. And I never asked you to.


What are you trying to say?
"It does not?"
"You don't exist?"
...


He asked how he was supposed to "prove" it. I told him he didnt have
to and I never asked him to. And dont want him to. It is irrelvant to
the argument in hand. Really.
didn't make it up on the spur of the moment to support my argument in this
thread - unless you'd rather believe I am capable of hacking Google's
archives to insert a brand new article and yet make it appear as if it were
posted almost seven years ago.


What are you talking about? I think you need to come down off your
high horse to be quite honest.


It seems to me that you are construing things a little bit
hastily.


Not really. This is getting plain silly : again. Richard has got all
on his horse because I cracked a joke. If it caused offence then I
apologise to those offended : to the rest ... :-;
Keith is right. You have a lot to learn about Usenet.
And you have a lot to learn too. Especially about making asumptions on
google pseudonyms.


Please quote what you are referring to.


He earlier mentioned his terms of service in this NG. As if it earns
you stripes.
This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend :

So you called me a liar, then you smiled about it, and then you accused me
of malicious damage.
Whatever. I give up.


I suggest you reread what you write before posting it off;
somehow, several others seem to misread it. For me,
interspersing an insult with a smiley does not exactly make
it better -- there are better means to convey a humorous
remark on usenet.


For you. For Keith. For Richard. For some others. Sorry. I'm
devastated. No really.

If you take a step back and pay attention to the real content of the
post you would see that it was attempting to be constructive and
pointing out that C does not wreck systems with every overrun.

And to suggest it does it ridiculous. Note : in no way am I condoning
overruns. There : I covered my ass.
it whats known in the real world as a bit of humour.

I don't quite see what anyone in the real world would find amusing about
being called a liar and a vandal.
I bet you dont find racist or sexist jokes funny eh? Do you get all
red in the face and demand them to take it back?


For me, it depends on the context whether I find them
tolerable, intolerable or funny. The latter usually only
if they are directed at the one telling the joke. And I
have indeed a liking for some kinds of non-pc jokes.
Somehow I doubt that it is the others who need a humour fluffer
or whatever to understand when and how you are funny.


See : humour is easy. I laughed at that.

<snip: Parts resembling the actual topic; tragic, I know>
You have refused to take the comment in the spirit it was intended :
and if "learning about usenet" is learning how to pamper to self
important guys like yourself then good luck.
If you provide more hints to the "spirit it was intended",
then you may get better responses.

Funnily, the estimated degree of self-importance for you
by far outweighs the one I'd assign to Richard Heathfield
or Keith Thompson.
Thats a matter of opinion : and you are entitled to yours. I realise
you come from the same school thought as Keith and Richard so fair
play to you. I would humbly point out that I tend to try and help when
I can in a plain and constructive manner : and I certainly dont post
repetitive net nanny posts every 3 seconds or tell people that
"globals" dont exist in C. Are some of you really real world
programmers? My killfile has 8 people in. Some of them even quote the
other in their signatures : it is a clique - nothing unique to this
group. The "etc." is a syntax error comment still makes me laugh.
In fact, you sound like something crawled up your lower
intestines and died.

I dont think you have paid any attention to what I'm saying on the "On
Subject" part of this thread. But its interesting how when the going
gets tough to see who really starts throwing the insults about. But,
of course, if you didnt mean it : add a smiley - sometimes it works.

C is a language : it can be made approachable by posters here. It can
also be made to seem like a dangerous monster. Some do a very good job
of the later.
-Michael

Mar 12 '06 #37
test
ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so


Mar 12 '06 #38
jaysome <ja*****@spamcop.com> wrote:
Keith Thompson wrote:
No, there is not always a result. One of the infinitely many possible
consequences of undefined behavior is that the code might not compile
in the first place. Other possibilities are that the program could do
nothing at all, or format your hard drive, or melt your monitor, or
make demons fly out of your nose.


I'd believe you if you could give me an example of a compiler that does
nothing at all, or formats my hard drive, or melts my monitor, or makes
demons fly out of my nose, when presented with the following code:

int main(void)
{
int i = 0;
i = i++;
return 0;
}


You do not understand. The simplistic examples which every high school
boy could understand are not the problem. The really complex expressions
involving pointers, arrays, and several side effects in several places,
_those_ are the real problem. The compiler must be able to optimise a
correctly written expression, even a complex one. If the price is that
we are not allowed to write an assignment, even a simple one, which is
dubious in the first place, then writing sane code is a small price to
pay for efficiency. Small price? It's no price at all - it's a bonus. I
really do not want to have to debug code which contains the above and
have to guess whether the bozo who wrote it meant i++; i=i; or i=i; i++;
in the first place.
Some people have bewailed this, and claimed that there should be a rule
which allows "obviously" well-meant undefined behaviour (usually the
kinds they themselves write), while disallowing "obviously" perverse UB
(always the kinds they can't wrap their head around) as strictily as it
is now. There's only one answer to that: fine, _write it then_. And make
sure it is as clear as the current Standard. Oddly enough, one rarely
hears anything of their new rules...

Richard
Mar 14 '06 #39
"Richard G. Riley" <rg****@gmail.com> wrote:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:

You just called Richard Heathfield a liar. I suggest you either back
up your accusation or apologize.


Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.

This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend : it whats known in
the real world as a bit of humour.


Actually, I gather that in Mr. Heathfield's part of the real world it's
what's known as an insufficient defense in a slander case. You're lucky
that he's not the kind to take legal umbrage easily.

Richard
Mar 14 '06 #40
Richard Bos said:
"Richard G. Riley" <rg****@gmail.com> wrote:
it whats known in
the real world as a bit of humour.
Actually, I gather that in Mr. Heathfield's part of the real world it's
what's known as an insufficient defense in a slander case.


Minor nit: It's written, so I believe it's actually libel.
You're lucky that he's not the kind to take legal umbrage easily.


And I'm lucky I'm not the kind of person to call people liars and vandals.
I'd hate to be that kind of person.

--
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)
Mar 14 '06 #41
>>What about commenting on the advice "not to learn c"? Any thoughts on
that? Or did they not impress you either? Or are your jumping to
protect Richards honor? I suspect Richard is big and ugly enough to do
that himself.


This is really not in a good taste. I expect lot of professional
attitude from people posting in here.
Words like *ugly* and pointing to someone personally really puts me
off.
Its not a school fight to impress or to show off by aiming at others
personally.
Hope such kind of behaviour is avoided

Mar 14 '06 #42
In article <dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Richard Bos said:
"Richard G. Riley" <rg****@gmail.com> wrote:
it whats known in
the real world as a bit of humour.
Actually, I gather that in Mr. Heathfield's part of the real world it's
what's known as an insufficient defense in a slander case.

Minor nit: It's written, so I believe it's actually libel.


[OT]

In these parts, the "slander" vs "libel" distinction applies for
civil cases, but the appropriate criminal code section lumps everything
together as "defamatory libel". So hereabouts, written words would
always be "libel", but spoken words could be termed either "slander"
or "libel".
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Mar 14 '06 #43
On 2006-03-14, Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
"Richard G. Riley" <rg****@gmail.com> wrote:
On 2006-03-12, Keith Thompson <ks***@mib.org> wrote:
>
> You just called Richard Heathfield a liar. I suggest you either back
> up your accusation or apologize.
>
Oh please. And I also called his pint a poof.

Or I could ask him to back up his claim.

This might have escaped your notice but I included a smiley and also
suggested he doctored the code to scare his friend : it whats known in
the real world as a bit of humour.


Actually, I gather that in Mr. Heathfield's part of the real world it's
what's known as an insufficient defense in a slander case.


You misspelled "libel".
You're lucky that he's not the kind to take legal umbrage easily.


I've heard that in most sane parts of the world, if something can be
shown to be sufficiently unlikely to be taken seriously by any third
party as to not do actual damage to the "victim"'s reputation, that is a
sufficient defense in a libel case. Unfortunately, for these purposes
I'm told that the UK's legal system is not as 'sane' as those in most
other parts of the world.

So, as long as he never actually visits there, he should be fine.
Mar 14 '06 #44
In article <sl**********************@random.yi.org>,
Jordan Abel <ra*******@gmail.com> wrote:
I've heard that in most sane parts of the world, if something can be
shown to be sufficiently unlikely to be taken seriously by any third
party as to not do actual damage to the "victim"'s reputation, that is a
sufficient defense in a libel case. Unfortunately, for these purposes
I'm told that the UK's legal system is not as 'sane' as those in most
other parts of the world. So, as long as he never actually visits there, he should be fine.


[OT]

Disclaimer: IANAL

UK law can be used to sue for "publication" in the UK,
even if neither party is a UK resident. A previous case has -already-
established that posting to a newsgroup that is available in the UK
qualifies as "publishing" in the UK, and the third-party libel
lawsuit scenario has -already- happened and was successful.

If a libel lawsuit is filed against someone in the UK and that
person choses not to defend against it (e.g. because they don't
want to bother with the expense of travelling and staying in the UK),
then the most likely result (for a properly-filed suit) would be
a default judgement. If the person then choose not to travel to the UK
in order to avoid collection upon the judgement, then the person
would also have to avoid doing business in the UK (even as simple
as ordering a CD from a UK distributor), as any funds or property
of theirs that enters UK jurisdiction would be subject to seizure.
{I don't have any information about other possible consequences.}
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Mar 14 '06 #45
On 2006-03-14, Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
In article <sl**********************@random.yi.org>,
Jordan Abel <ra*******@gmail.com> wrote:
I've heard that in most sane parts of the world, if something can be
shown to be sufficiently unlikely to be taken seriously by any third
party as to not do actual damage to the "victim"'s reputation, that is a
sufficient defense in a libel case. Unfortunately, for these purposes
I'm told that the UK's legal system is not as 'sane' as those in most
other parts of the world.

So, as long as he never actually visits there, he should be fine.


[OT]

Disclaimer: IANAL

UK law can be used to sue for "publication" in the UK,
even if neither party is a UK resident. A previous case has -already-
established that posting to a newsgroup that is available in the UK
qualifies as "publishing" in the UK, and the third-party libel
lawsuit scenario has -already- happened and was successful.

If a libel lawsuit is filed against someone in the UK and that
person choses not to defend against it (e.g. because they don't
want to bother with the expense of travelling and staying in the UK),
then the most likely result (for a properly-filed suit) would be
a default judgement. If the person then choose not to travel to the UK
in order to avoid collection upon the judgement, then the person
would also have to avoid doing business in the UK (even as simple
as ordering a CD from a UK distributor), as any funds or property
of theirs that enters UK jurisdiction would be subject to seizure.
{I don't have any information about other possible consequences.}


Say both parties are citizens of the US. Could the one who sued for
libel then, subsequently, be sued in the US for malicious prosecution,
barratry, or something like that? [they sued in UK jurisdiction,
presumably, because they knew that what was done was not in fact libel,
and were taking advantage of the lax standards of proof in the UK, or
even of the likelihood of a default judgement.]

http://en.wikipedia.org/wiki/Malicious_prosecution
http://en.wikipedia.org/wiki/Barratry
http://en.wikipedia.org/wiki/Forum_shopping
Mar 14 '06 #46
In article <sl**********************@random.yi.org>,
Jordan Abel <ra*******@gmail.com> wrote:
[still OT]
Say both parties are citizens of the US. Could the one who sued for
libel then, subsequently, be sued in the US for malicious prosecution,
barratry, or something like that? [they sued in UK jurisdiction,
presumably, because they knew that what was done was not in fact libel,
and were taking advantage of the lax standards of proof in the UK, or
even of the likelihood of a default judgement.]


There's a maxim that goes something like "Anyone can be sued for any
reason" with its addendum "The difficulty is getting it to stick."
The foundation of libel (and slander and defamation) is that
there is damage (or attempted damage) to someone's reputation.

Defence against libel lies in showing that the circumstances did not
give rise to damage to the reputation, or in showing that the damage
was lawful within the constraints of the relevant law.

It is entirely possible for a court to rule that libel (damage to
reputation) has occured, but that the defendant had a lawful excuse and
so cannot be punished for the libelous act. Judges have been known to
issue harsh scoldings in cases where the circumstances do not permit
them to convict; in many countries, those scoldings become matters of
public record.

The UK does not have lax standards of proof for libel: what it
has is a different set of lawful excuses.

In USA law, if a libelous statement is found to be true,
then the truth of that statement is considered an "absolute defence".
That would not stop the judge from ruling that a statement was
indeed shamefully libelous: it just stops them from doing anything about it.

Also, the USA has a relatively new law of "criminal libel", in
which the truth of the statement is NOT a defence, if the courts are
satisfied that the statement was made "in reckless disregard for the truth".
Thus if a tabloid publishes a shopping list of invented attacks on
a celeb, one of which happpens by accident to be true, then the
celeb can sue on the whole without having to implicitly admit the
truth of the one portion by -not- sueing about the one.

In Canadian federal law, the truth of a statement is not a defence --
though in some circumstances, a reasonable -belief- in the truth of the
statement is. -Every- available defence is qualified by the requirement
that the statements did not go too far beyond what was "reasonable"
under the circumstances. Thus slagging someone a little is sometimes
excusable, but slagging them a lot is not, even if everything said was
true.

UK law (or precident) goes further and [if I understand correctly]
basically says, "If you don't have a good reason to actively say
these things, then don't say them." What qualifies as a good enough
reason has been evolving over the last decade or so, with more
"public interest" allowances being accepted.
I would -think- that in order for someone in the US to prove
malicious prosecution or barratry with respect to a libel suit
that was run in the UK, it would probably have to be proved
that there was no -reasonable- chance that the original libel
lawsuit could succeed there, or that there were ulterior motives
behind the filing of the suit. But court rulings continually
surprise me...
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Mar 14 '06 #47
On 2006-03-14, Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
In article <sl**********************@random.yi.org>,
Jordan Abel <ra*******@gmail.com> wrote:
[still OT]

It is entirely possible for a court to rule that libel (damage to
reputation) has occured, but that the defendant had a lawful excuse and
so cannot be punished for the libelous act. Judges have been known to
issue harsh scoldings in cases where the circumstances do not permit
them to convict; in many countries, those scoldings become matters of
public record.

The UK does not have lax standards of proof for libel: what it
has is a different set of lawful excuses.
There is, however, the fact that you don't have to prove it at all if
the defendant can't or won't travel to the UK.
In USA law, if a libelous statement is found to be true, then the
truth of that statement is considered an "absolute defence". That
would not stop the judge from ruling that a statement was indeed
shamefully libelous: it just stops them from doing anything about it.
What I meant is that if one US citizen sues another in the UK for libel
[as described in previous posts], can the defendant sue the plaintiff
back in US court for malicious prosecution, either purely on the grounds
that (even though it would have succeeded in either jurisdiction) the
plaintiff was attempting to pile the additional expense of travel on top
of the damages; or based on the attempt by the plaintiff to find a more
favorable, or at least more difficult to avoid default judgement, venue?
I would -think- that in order for someone in the US to prove malicious
prosecution or barratry with respect to a libel suit that was run in
the UK, it would probably have to be proved that there was no
-reasonable- chance that the original libel lawsuit could succeed
there, or that there were ulterior motives behind the filing of the
suit. But court rulings continually surprise me...


And that answers my question, basically.

Though, what's still not clear to me is whether it would have to be no
reasonable chance that the original lawsuit could succeed in the UK, or
no reasonable chance that it could succeed in the US? I.e., does the US
even recognize that UK law applies to such a case [where both parties
are resident US citizens and the allegedly libelous writing is posted in
an international forum]?
Mar 14 '06 #48
Jordan Abel <ra*******@gmail.com> writes:
[stuff about libel]


Surely there must be some better place to conduct this
discussion.
--
"The lusers I know are so clueless, that if they were dipped in clue
musk and dropped in the middle of pack of horny clues, on clue prom
night during clue happy hour, they still couldn't get a clue."
--Michael Girdwood, in the monastery
Mar 14 '06 #49
On 2006-03-14, Ben Pfaff <bl*@cs.stanford.edu> wrote:
Jordan Abel <ra*******@gmail.com> writes:
[stuff about libel]


Surely there must be some better place to conduct this
discussion.


Probably, but it came up in here, and the discussion was between people
who are regulars in here. I'm pretty much satisfied with the answers I
got.
Mar 14 '06 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
2
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function...
6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
5
by: devereaux | last post by:
I'm trying to run a script and it's throwing the following error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR in openfile.php on line 41 Here is the openfile.php file and I have...
13
by: bintom | last post by:
I ran the following simple code in C++ and got unexpected results: float f = 139.4; cout << f; Output: 139.399994;
2
by: =?Utf-8?B?QXJtaW4gR2FsbGlrZXI=?= | last post by:
Hi I've got an unexpected error in a unit test. I want to test a activity from Windows Workflow Foundation (WF). First, I executed the test outside of the activity just in the test-init...
11
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type: application/xmsdownload"); header("Content-Disposition:...
14
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up...
14
by: Padfoot153 | last post by:
Hey, I'm getting the error: Parse error: syntax error, unexpected T_VARIABLE in /Users/Oscar/AwesomeSongz/userCake/profile.php on line 7 with this code <?php...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.