comp.lang.c - 25 new messages in 12 topics - digest
comp.lang.c
http://groups.google.com/group/comp.lang.c?hl=en
Today's topics:
* ANNOUNCE: WinGDB - debugging with GDB under Visual Studio - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c/t/caa9b97bbee41cd4?hl=en
* Various ways to get month name from inbuilt C library - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/7aa38ff82f37f58e?hl=en
* Beginner's guide to MinGW? - 8 messages, 5 authors
http://groups.google.com/group/comp.lang.c/t/e2cff1c3cf36ab5f?hl=en
* Has thought been given given to a cleaned up C? Possibly called C+. - 4
messages, 3 authors
http://groups.google.com/group/comp.lang.c/t/5954dc70a43f9f8e?hl=en
* Letter sent to Apress with concerns about Peter Seebach's online behavior -
1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/482b38643777da3c?hl=en
* parsing practice - 3 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/69eefd7d02a113a3?hl=en
* -2147483648 and gcc optimisation, all sorts of different results - 2
messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/1e4020710ed342ba?hl=en
* Efficency and the standard library - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/ad9fea19f2f7dd61?hl=en
* question about macro? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/78ed6f536b032cfc?hl=en
* Best way/library to draw individual pixels on screen? <OT> - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c/t/bf4e0288d8537985?hl=en
* Cheap Wholesale A&F Shirt, Armani Shirt, Christan Audigier Coat, Bape Coat,
Scarf etc free shipping (www.vipchinatrade.com) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/1700bdaceaed6ee9?hl=en
* Stylistic questions on UNIX C coding. - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/51d2b24a60d73f18?hl=en
==============================================================================
TOPIC: ANNOUNCE: WinGDB - debugging with GDB under Visual Studio
http://groups.google.com/group/comp.lang.c/t/caa9b97bbee41cd4?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 2:59 am
From: gazelle@shell.xmission.com (Kenny McCormack)
In article <30454ba2-5c31-472a-8003-c92be454dea5@q23g2000yqd.googlegroups.com>,
Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
...
>you used to have to be careful where you installed it. It doesn't (or
>didn't) like spaces in pathnames, hence "C:\Program Files\MinGW" is
>out for a start.
But I assume that C:\progra~1\MinGW would work just fine.
That's how I would do it.
==============================================================================
TOPIC: Various ways to get month name from inbuilt C library
http://groups.google.com/group/comp.lang.c/t/7aa38ff82f37f58e?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 3:34 am
From: Nick Keighley
On 10 Mar, 14:14, ralt...@xs4all.nl (Richard Bos) wrote:
> I don't know that [asctime()] is outdated; I think that it never was a reasonable
> format to use in the first place.
isn't it reasonably common format in the US? Though mixing the time up
in the middle of the date does seem weird!
Sun Sep 16 01:03:52 1973\n\0
==============================================================================
TOPIC: Beginner's guide to MinGW?
http://groups.google.com/group/comp.lang.c/t/e2cff1c3cf36ab5f?hl=en
==============================================================================
== 1 of 8 ==
Date: Thurs, Mar 11 2010 3:40 am
From: Nick Keighley
On 11 Mar, 10:58, gaze...@shell.xmission.com (Kenny McCormack) wrote:
> In article <8570349a-efc2-432a-b7e4-61e88c299...@q16g2000yqq.googlegroups.com>,
> Nick Keighley <nick_keighley_nos...@hotmail.com> wrote:
> >Microsoft's "Visual C++ Express" is another free compiler. And despite
> >the weird name it compiles bog-standard C. Reasonable IDE. Some say it
> >is a very large download. I can't say I noticed.
>
> Note that compilers from MS only compile some old version of standard C.
> MS has not kept up-to-date with the current standard.
but happily Microsoft are completly up to date with the most portable
version of the C standard (1989/1990). They do try and encourage you
to use some odd extensions though. [disable the warning about "using
unsafe function strcpy"]
== 2 of 8 ==
Date: Thurs, Mar 11 2010 3:51 am
From: Branimir Maksimovic
On Thu, 11 Mar 2010 03:40:45 -0800 (PST)
Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
> On 11 Mar, 10:58, gaze...@shell.xmission.com (Kenny McCormack) wrote:
> > In article
> > <8570349a-efc2-432a-b7e4-61e88c299...@q16g2000yqq.googlegroups.com>,
> > Nick Keighley <nick_keighley_nos...@hotmail.com> wrote:
>
> > >Microsoft's "Visual C++ Express" is another free compiler. And
> > >despite the weird name it compiles bog-standard C. Reasonable IDE.
> > >Some say it is a very large download. I can't say I noticed.
> >
> > Note that compilers from MS only compile some old version of
> > standard C. MS has not kept up-to-date with the current standard.
>
> but happily Microsoft are completly up to date with the most portable
> version of the C standard (1989/1990). They do try and encourage you
> to use some odd extensions though. [disable the warning about "using
> unsafe function strcpy"]
Is C++ completely compatible with C 89/90? Basic idea of C++ is
to be compatible with C, while you can use syntactic sugar in
order to write less code.
Problem is now if they are not compatible and let's say if you write
C/C++ you can;t write C99/C++ ;)
Technically one would expect same behavior, but if one is used to
C++ now it is difficult to move to C99 or vice versa.
Greets
Sometimes online sometimes not
== 3 of 8 ==
Date: Thurs, Mar 11 2010 4:09 am
From: Richard
Branimir Maksimovic <bmaxa@hotmail.com> writes:
> On Thu, 11 Mar 2010 03:40:45 -0800 (PST)
> Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
>
>> On 11 Mar, 10:58, gaze...@shell.xmission.com (Kenny McCormack) wrote:
>> > In article
>> > <8570349a-efc2-432a-b7e4-61e88c299...@q16g2000yqq.googlegroups.com>,
>> > Nick Keighley <nick_keighley_nos...@hotmail.com> wrote:
>>
>> > >Microsoft's "Visual C++ Express" is another free compiler. And
>> > >despite the weird name it compiles bog-standard C. Reasonable IDE.
>> > >Some say it is a very large download. I can't say I noticed.
>> >
>> > Note that compilers from MS only compile some old version of
>> > standard C. MS has not kept up-to-date with the current standard.
>>
>> but happily Microsoft are completly up to date with the most portable
>> version of the C standard (1989/1990). They do try and encourage you
>> to use some odd extensions though. [disable the warning about "using
>> unsafe function strcpy"]
>
> Is C++ completely compatible with C 89/90? Basic idea of C++ is
> to be compatible with C, while you can use syntactic sugar in
> order to write less code.
LOL. What a load of nonsense. That is not the "Basic idea of C++" at
all. Where on earth did you learn that?
> Problem is now if they are not compatible and let's say if you write
> C/C++ you can;t write C99/C++ ;)
>
> Technically one would expect same behavior, but if one is used to
> C++ now it is difficult to move to C99 or vice versa.
No it isn't. They are different languages with a similar subset.
--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c
== 4 of 8 ==
Date: Thurs, Mar 11 2010 4:19 am
From: Branimir Maksimovic
On Thu, 11 Mar 2010 13:09:16 +0100
Richard <rgrdev_@gmail.com> wrote:
> Branimir Maksimovic <bmaxa@hotmail.com> writes:
>
> > On Thu, 11 Mar 2010 03:40:45 -0800 (PST)
> > Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
> >
> >> On 11 Mar, 10:58, gaze...@shell.xmission.com (Kenny McCormack)
> >> wrote:
> >> > In article
> >> > <8570349a-efc2-432a-b7e4-61e88c299...@q16g2000yqq.googlegroups.com>,
> >> > Nick Keighley <nick_keighley_nos...@hotmail.com> wrote:
> >>
> >> > >Microsoft's "Visual C++ Express" is another free compiler. And
> >> > >despite the weird name it compiles bog-standard C. Reasonable
> >> > >IDE. Some say it is a very large download. I can't say I
> >> > >noticed.
> >> >
> >> > Note that compilers from MS only compile some old version of
> >> > standard C. MS has not kept up-to-date with the current standard.
> >>
> >> but happily Microsoft are completly up to date with the most
> >> portable version of the C standard (1989/1990). They do try and
> >> encourage you to use some odd extensions though. [disable the
> >> warning about "using unsafe function strcpy"]
> >
> > Is C++ completely compatible with C 89/90? Basic idea of C++ is
> > to be compatible with C, while you can use syntactic sugar in
> > order to write less code.
>
> LOL. What a load of nonsense. That is not the "Basic idea of C++" at
> all. Where on earth did you learn that?
Well, first target audience for C++ were C programmers.
So basically C with classes was original idea.
>
> > Problem is now if they are not compatible and let's say if you write
> > C/C++ you can;t write C99/C++ ;)
> >
> > Technically one would expect same behavior, but if one is used to
> > C++ now it is difficult to move to C99 or vice versa.
>
> No it isn't. They are different languages with a similar subset.
Oh, unfortunately they are different languages, not fortunately.
Have you ever thought why is C99 not so successful and widely
adopted? VC++ note "++" in it's name ;)
Greets
>
>
Sometimes online sometimes not
== 5 of 8 ==
Date: Thurs, Mar 11 2010 4:40 am
From: Richard
Branimir Maksimovic <bmaxa@hotmail.com> writes:
> On Thu, 11 Mar 2010 13:09:16 +0100
> Richard <rgrdev_@gmail.com> wrote:
>
>> Branimir Maksimovic <bmaxa@hotmail.com> writes:
>>
>> > On Thu, 11 Mar 2010 03:40:45 -0800 (PST)
>> > Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
>> >
>> >> On 11 Mar, 10:58, gaze...@shell.xmission.com (Kenny McCormack)
>> >> wrote:
>> >> > In article
>> >> > <8570349a-efc2-432a-b7e4-61e88c299...@q16g2000yqq.googlegroups.com>,
>> >> > Nick Keighley <nick_keighley_nos...@hotmail.com> wrote:
>> >>
>> >> > >Microsoft's "Visual C++ Express" is another free compiler. And
>> >> > >despite the weird name it compiles bog-standard C. Reasonable
>> >> > >IDE. Some say it is a very large download. I can't say I
>> >> > >noticed.
>> >> >
>> >> > Note that compilers from MS only compile some old version of
>> >> > standard C. MS has not kept up-to-date with the current standard.
>> >>
>> >> but happily Microsoft are completly up to date with the most
>> >> portable version of the C standard (1989/1990). They do try and
>> >> encourage you to use some odd extensions though. [disable the
>> >> warning about "using unsafe function strcpy"]
>> >
>> > Is C++ completely compatible with C 89/90? Basic idea of C++ is
>> > to be compatible with C, while you can use syntactic sugar in
>> > order to write less code.
>>
>> LOL. What a load of nonsense. That is not the "Basic idea of C++" at
>> all. Where on earth did you learn that?
> Well, first target audience for C++ were C programmers.
> So basically C with classes was original idea.
So what? Its nothing to so with "syntactic sugar" to write less code.
>>
>> No it isn't. They are different languages with a similar subset.
> Oh, unfortunately they are different languages, not fortunately.
> Have you ever thought why is C99 not so successful and widely
> adopted? VC++ note "++" in it's name ;)
They are different languages. I dont know what you are trying to say. C
was always going to fall by the wayside as OO language attracted the
masses.
>
> Greets
>
>>
>>
--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c
== 6 of 8 ==
Date: Thurs, Mar 11 2010 5:52 am
From: REH
On Mar 11, 7:19 am, Branimir Maksimovic <bm...@hotmail.com> wrote:
> Oh, unfortunately they are different languages, not fortunately.
Why unfortunately? If they were the same, why even bother having both?
REH
== 7 of 8 ==
Date: Thurs, Mar 11 2010 6:05 am
From: Branimir Maksimovic
On Thu, 11 Mar 2010 05:52:02 -0800 (PST)
REH <spamjunk@stny.rr.com> wrote:
> On Mar 11, 7:19 am, Branimir Maksimovic <bm...@hotmail.com> wrote:
> > Oh, unfortunately they are different languages, not fortunately.
>
> Why unfortunately? If they were the same, why even bother having both?
>
Because one want to program in C and use some features from C++
on top of C code.
I mean things would be simpler. Basic idea is compatibility.
and c++ is C89/90 based language with added exceptions,
templates (automatic calling of init/deinit, copy, assign functions
that take first parameter as struct) and syntactic sugar.
Greets
Sometimes online sometimes not
== 8 of 8 ==
Date: Thurs, Mar 11 2010 6:13 am
From: "osmium"
REH wrote:
> On Mar 11, 7:19 am, Branimir Maksimovic <bm...@hotmail.com> wrote:
>> Oh, unfortunately they are different languages, not fortunately.
>
> Why unfortunately? If they were the same, why even bother having both?
Surely, someone must have used the dreaded word "subset" in this thread.
The notion of a subset can be very helpful. For example, I don't know of
*anyone* that has a handle on the complete list of words used in the English
language.
This is not meant to imply that a subset in the C/C++ case was *possible*,
just that it could have been a nice goal. Which is not meant to imply that
it in fact was a goal.
As I see it, the C-C++ relationship was "get the camel into the tent".
==============================================================================
TOPIC: Has thought been given given to a cleaned up C? Possibly called C+.
http://groups.google.com/group/comp.lang.c/t/5954dc70a43f9f8e?hl=en
==============================================================================
== 1 of 4 ==
Date: Thurs, Mar 11 2010 3:54 am
From: Nick Keighley
On 11 Mar, 09:27, Richard <rgrd...@gmail.com> wrote:
> Nick Keighley <nick_keighley_nos...@hotmail.com> writes:
> > On 10 Mar, 18:13, Nick <3-nos...@temporary-address.org.uk> wrote:
<snip>
> >> Really you need to be able to define new operators, even if this is just
> >> syntactic sugar for functions. Give them all the same precedence and
> >> off you go.
>
> > Algol-68, of course, allowed you to define precedence as well...
>
> Oh for goodness sake. Stop mentioning Algol. It's gone.
he was talking about language design. Algol-68 tackeled this problem.
Maybe it's gone because its solution was unsatisfactory. But it was an
attempt.
== 2 of 4 ==
Date: Thurs, Mar 11 2010 5:23 am
From: Ben Bacarisse
Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
> (Sorry, have to drop .moderated, as for some unknown reason GNUS refuses
> to post there.)
>
> Keith Thompson <kst-u@mib.org> writes:
>> Thomas Richter <thor@math.tu-berlin.de> writes:
>>> Flash Gordon wrote:
>> [...]
>>>> My experience is that operator overloading leads to confusion for
>>>> experienced users.
>>
>> It certainly can.
>>
>>> In most cases, it should be avoided. The C++ overloading of >> and <<
>>> for IO operations is definitely a pretty bad idea. There are rare
>>> cases where it does make sense because the operator has a very natural
>>> meaning (vector addition, matrix multiplication). It is a feature that
>>> should be used with care. But >> and << for I/O is not one of them.
>>
>> I don't agree. It's an arbitrary choice of symbol that does have
>> some mnemonic value; the arrow indicates the direction in which
>> the data flows.
>
> 'Flows', eh?
>
> So in
> s >> a >> b >> c;
> c flowed out first as it's the furthest from the source?
Using the word "flow" does not mean you must forget the associativity
of the operator. The data for c (as you know) "flows" from the stream
that results from calculating (s >> a >> b).
Because left-associativity[1] is so common, I see this pattern in my
head without having to think about it.
[1] Check: "left" yes, pretty sure I mean left -- otherwise known as
"UK driving associativity" :-)
<snip>
--
Ben.
== 3 of 4 ==
Date: Thurs, Mar 11 2010 5:56 am
From: Ben Bacarisse
Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
> pacman@kosh.dhis.org (Alan Curry) writes:
>> In article <4b97b986.17080734@news.xs4all.nl>,
>> Richard Bos <rlbos@xs4all.nl> wrote:
>> |"bartc" <bartc@freeuk.com> wrote:
>> |
>> |> jacob navia wrote:
>> |> >
>> |> > a+b <--> b+a
>> |> > a*b <--> b*a
>> |>
>> |> What do you have against a-b and a/b?
>> |
>> |And against vector multiplication?
>>
>> scalar*vector follows the rule just fine. And vector*vector as long as you
>> mean dot product. Cross product is exactly where you have gone too far if you
>> overload the "*" operator for it.
>>
>> Matrix multiplication is just crazy. I don't see why the mathematicians
>> insist on calling it "multiplication" at all.
>
> Because it is, in that ring.
What ring? Matrices don't (in general) form a ring. They are not
even always defined over one.
> An objection based on non-commutativity
> is to me as toothless as an objection based on a ring not being an
> integral domain (having zero divisors). Which is toothless.
I agree, but it seems like an odd point to being up. There's no
evidence that Alan Curry was worried about non-commutativity when he
described matrix multiplication as "crazy".
If it matters, I agree with you. It seems perfectly reasonable to me
to call the matrix operation "multiplication" if only because of the
special case where it /does/ generate a ring.
--
Ben.
== 4 of 4 ==
Date: Thurs, Mar 11 2010 6:18 am
From: William Hughes
On Mar 10, 6:48 pm, pac...@kosh.dhis.org (Alan Curry) wrote:
> Matrix multiplication is just crazy. I don't see why the mathematicians
> insist on calling it "multiplication" at all.
Matrix multiplication is not "just crazy" it
corresponds to composition of linear
transforms. The operation of taking two operators
and forming a third by composition is frequently
called multiplication.
- William Hughes
==============================================================================
TOPIC: Letter sent to Apress with concerns about Peter Seebach's online
behavior
http://groups.google.com/group/comp.lang.c/t/482b38643777da3c?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 5:04 am
From: Eric Sosman
On 3/11/2010 4:12 AM, Mark Bluemel wrote:
> John Bode wrote:
>> On Mar 10, 8:39 am, spinoza1111 <spinoza1...@yahoo.com> wrote:
>>> A letter complaining about Peter Seebach's online behavior in this
>>> forum and in comp.lang.c.moderated has been sent to Apress management.
>>
>> Serious question: what are you expecting to happen as a result of this
>> letter?
>
> A sound spanking to be administered? Seebs to be sent to the naughty
> step? $diety only knows how Spinoza thinks the world works.
The chances that even $diety knows are slim.
--
Eric Sosman
esosman@ieee-dot-org.invalid
==============================================================================
TOPIC: parsing practice
http://groups.google.com/group/comp.lang.c/t/69eefd7d02a113a3?hl=en
==============================================================================
== 1 of 3 ==
Date: Thurs, Mar 11 2010 5:05 am
From: "Bill Cunningham"
"Ike Naar" <ike@localhost.claranet.nl> wrote in message
news:hn9agl$j6p$1@news.eternal-september.org...
> If argc = 1, argv[0] is a valid string but argv[1] = NULL.
> You wouldn't want to dereference argv[1] in that case.
That's another thing I tried without really understanding what I was
doing and it worked. When I tried argv[1] without the dereference I got an
error somethng like "pointer to int..." something. So I put in the *argv[1]
and it worked. Except for the seg. fault.
Bill
== 2 of 3 ==
Date: Thurs, Mar 11 2010 5:09 am
From: "Bill Cunningham"
"Robbie Hatley" <see.my.signature@for.my.contact.info> wrote in message
news:JsydnQQ2VaIeMQXWnZ2dnUVZ_v6dnZ2d@giganews.com...
[snip]
> According to section 5.1.2.2.1 of the C standard:
> - argc must be non-negative
> - argv[argc] must be a null pointer
> - if argc is greater than zero, then argv[0] is NOT an argument,
> it's the name of the program, or an empty string if the program
> name is not available.
> - if argc is greater than one, argv[1] through argv[argc-1]
> will be your program parameters.
>
> In other words, argc is "count of items in argv", NOT "count of
> arguments".
Oh I see.
And since the zeroeth element of argc is always
> reserved for the program name (whether it's available or not),
> if argc is non-zero, argc = "number of arguments + 1".
>
> (The standard doesn't mention under what conditions argc
> is 0. I've never seen argc==0 in my life. I suppose
> a compiler that doesn't support arguments could set it
> to 0 to indicate that arguments aren't supported.)
>
> In practice, if there are no arguments, argc will usually be 1.
>
> If argc is 1, your first "if" will fail, and your second
> "if" will cause an ILLEGAL MEMORY ACCESS at runtime.
>
> Hence the first "if" should read:
>
> if (argc < 2) {
> fprintf(stderr, "parsing usage error\n");
> return 1;
> }
>
> Insisting that argc be at least 2 is the only way to insure
> that referencing "argv[1]" is legal.
>
> --
> Cheers,
> Robbie Hatley
> lonewolf at well dot com
> www dot well dot com slant tilde lonewolf slant
>
>
== 3 of 3 ==
Date: Thurs, Mar 11 2010 5:11 am
From: "Bill Cunningham"
"Nick" <3-nospam@temporary-address.org.uk> wrote in message
news:87eijr8ea7.fsf@temporary-address.org.uk...
> No it doesn't. It never touches stdin.
>
> It uses the parameters passed in argv, but that's nothing at all to do
> with "taking from stdin".
It takes input from the keyboard. I thought that was stdin.
Bill
==============================================================================
TOPIC: -2147483648 and gcc optimisation, all sorts of different results
http://groups.google.com/group/comp.lang.c/t/1e4020710ed342ba?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Mar 11 2010 5:43 am
From: "tom_usenet@optusnet.com.au"
I'm surprised at the different results I can get from code with and
without optimisation where overflow is involved.
I suspect this was "done to death" about 20 years ago, but
I can't find anything in comp.lang.c matching this. Is this
the "if you overflow the compiler can do whatever it likes"
clause?
The original problem I was trying to solve is why a simple
embedded "printf("%ld")" was printing random garbage when
handed -2147483648.
Here are the results for the following simple program with different
optimisation levels, in all cases "-O1" gives sane results and "-O2"
gives remarkably creative results.
The problems are:
1 - With "-O2" the second test in the following is optimised out:
as it "can't be true". Unless (num == -2147483648) in which
case it IS true, and is what I'm trying to correct for in
the function I was trying to fix.
if (num < 0L) num = -num;
if (num < 0L) stillNeg = 1;
2 - "-2147483647 + 1 == -2147483647" ???
3 - "-2147483647 == --2147483647" ???
This is the "sane" one without optimisation.
$ gcc --version
gcc (GCC) 4.3.4 20090804 (release) 1
$ gcc -Wall -O1 -o ox2 ox2.c
$ ./ox2
Function calls
2147483646
2147483647
-2147483648 Still negative
2147483647
2147483646
For loop
num = 2147483646 vnum = 2147483646
num = 2147483647 vnum = 2147483647
num = -2147483648 neg vnum = -2147483648 neg
num = 2147483647 vnum = 2147483647
num = 2147483646 vnum = 2147483646
This is the insane one with optimisation.
$ gcc -Wall -O2 -o ox2 ox2.c
$ ./ox2
Function calls
2147483646
2147483647
-2147483648 *** Missed the second test ***
2147483647
2147483646
For loop
num = 2147483646 vnum = 2147483646
num = 2147483647 vnum = 2147483647
num = 2147483647 vnum = -2147483648
num = 2147483647 vnum = -2147483647
num = 2147483647 vnum = -2147483646
^^ That got stuck ^^ ^^ That is negating when it shouldn't **
Here's the test code. Apologies for the "crammed style", I don't
usually write code that looks this bad:
#include <stdio.h>
void tneg(long num);
void tneg(long num)
{
int stillNeg = 0;
if (num < 0L) num = -num;
if (num < 0L) stillNeg = 1;
printf("%ld %s\n", num, (stillNeg)? " Still negative" : "");
}
int main(int argc, char ** argv)
{
long count;
long test, vtest, num, vnum;
printf("Function calls\n");
tneg((long)0x7ffffffe);
tneg((long)0x7fffffff);
tneg((long)0x80000000);
tneg((long)0x80000001);
tneg((long)0x80000002);
printf("For loop\n");
vnum = (argc == 5) ? 5 : 0x7ffffffe;
num = 0x7ffffffe;
for (count = 0; count < 5; count++)
{
int stillNeg = 0, vstillNeg = 0;
test = num; vtest = vnum;
if (test < 0) test = - test;
if (test < 0) stillNeg = 1;
if (vtest < 0) vtest = - vtest;
if (vtest < 0) vstillNeg = 1;
printf("num = %ld %s ", test, (stillNeg)? " neg" : " ");
printf("vnum = %ld %s\n", vtest, (vstillNeg)? " neg" : "");
num += 1; vnum += 1;
}
return 0;
}
== 2 of 2 ==
Date: Thurs, Mar 11 2010 6:59 am
From: Ben Bacarisse
"tom_usenet@optusnet.com.au" <tom_usenet@optusnet.com.au> writes:
> I'm surprised at the different results I can get from code with and
> without optimisation where overflow is involved.
>
> I suspect this was "done to death" about 20 years ago, but
> I can't find anything in comp.lang.c matching this. Is this
> the "if you overflow the compiler can do whatever it likes"
> clause?
Looks like it, yes.
> The original problem I was trying to solve is why a simple
> embedded "printf("%ld")" was printing random garbage when
> handed -2147483648.
That sounds quite different. For the "long int" that you seem to be
using it would be a library bug for printf("%ld", x) to print anything
but -2147483648. Did you mean that printf is being handed something
apparently random when you expected it to be handed -2147483648?
> Here are the results for the following simple program with different
> optimisation levels, in all cases "-O1" gives sane results and "-O2"
> gives remarkably creative results.
>
> The problems are:
>
> 1 - With "-O2" the second test in the following is optimised out:
> as it "can't be true". Unless (num == -2147483648) in which
> case it IS true, and is what I'm trying to correct for in
> the function I was trying to fix.
>
> if (num < 0L) num = -num;
> if (num < 0L) stillNeg = 1;
From the point of view of the C language it's not quite that "it can't
be true" -- it's more a case of "either it's true or undefined
behaviour has occurred". The net effect is the same, in that the
compiler is using this undefined behaviour as permission to conclude
that the second test is redundant.
I hope that does not sound like too much splitting of hairs. It's
useful to distinguish between what the C standard says and what a
compiler decides to do as a result.
> 2 - "-2147483647 + 1 == -2147483647" ???
I don't see where this happens in your code. If -2147483647 is
representable in your long int type (and it is from you example below)
then the above would be a bug. -2147483647 + 1 must be -2147483646.
[Guessing here: did you mean "2147483647 + 1 == 2147483647"? If so,
the compiler can do pretty much what it likes since 2147483647 + 1 is
undefined with the types you are using.]
> 3 - "-2147483647 == --2147483647" ???
Due to C's parsing rules, -- is not the same as - - but I know what you
are saying here.
With normal 32-but integers, if you see that -(-2147483647) !=
2147483647 then you would have bug but, again, I don't see that in
your code.
> This is the "sane" one without optimisation.
>
> $ gcc --version
> gcc (GCC) 4.3.4 20090804 (release) 1
>
> $ gcc -Wall -O1 -o ox2 ox2.c
> $ ./ox2
> Function calls
> 2147483646
> 2147483647
> -2147483648 Still negative
> 2147483647
> 2147483646
> For loop
> num = 2147483646 vnum = 2147483646
> num = 2147483647 vnum = 2147483647
> num = -2147483648 neg vnum = -2147483648 neg
> num = 2147483647 vnum = 2147483647
> num = 2147483646 vnum = 2147483646
>
> This is the insane one with optimisation.
>
> $ gcc -Wall -O2 -o ox2 ox2.c
> $ ./ox2
> Function calls
> 2147483646
> 2147483647
> -2147483648 *** Missed the second test ***
> 2147483647
> 2147483646
> For loop
> num = 2147483646 vnum = 2147483646
> num = 2147483647 vnum = 2147483647
> num = 2147483647 vnum = -2147483648
> num = 2147483647 vnum = -2147483647
> num = 2147483647 vnum = -2147483646
>
> ^^ That got stuck ^^ ^^ That is negating when it shouldn't **
The compiler is probably unrolling the loop[1] and can thus tell that num
overflows. It is permitted to make num += 1 whatever it likes. It
can't tell that vnum overflows because you (deliberately, I am sure)
made it depend on argc but it can (and, I think, does) assume that
there is no point in testing for vtest < 0 (vtest being a copy of
vnum) since it starts positive and is only incremented.
[1] It only needs to unroll one loop body to see that num hits its
maximum value and the optimiser will always try to unroll one loop to
put the test at the bottom. Change the initial value so that it is
one less and you will see that num and vnum now mirror each other.
> Here's the test code. Apologies for the "crammed style", I don't
> usually write code that looks this bad:
>
> #include <stdio.h>
>
> void tneg(long num);
> void tneg(long num)
> {
> int stillNeg = 0;
> if (num < 0L) num = -num;
> if (num < 0L) stillNeg = 1;
> printf("%ld %s\n", num, (stillNeg)? " Still negative" : "");
> }
>
> int main(int argc, char ** argv)
> {
> long count;
> long test, vtest, num, vnum;
>
> printf("Function calls\n");
> tneg((long)0x7ffffffe);
> tneg((long)0x7fffffff);
> tneg((long)0x80000000);
> tneg((long)0x80000001);
> tneg((long)0x80000002);
FYI: these last three are implementation defined conversions (i.e. the
C language does not say exactly what happens). 0x80000000 is a
positive number that can't be represented in your long type.
> printf("For loop\n");
> vnum = (argc == 5) ? 5 : 0x7ffffffe;
> num = 0x7ffffffe;
> for (count = 0; count < 5; count++)
> {
> int stillNeg = 0, vstillNeg = 0;
>
> test = num; vtest = vnum;
> if (test < 0) test = - test;
> if (test < 0) stillNeg = 1;
> if (vtest < 0) vtest = - vtest;
> if (vtest < 0) vstillNeg = 1;
> printf("num = %ld %s ", test, (stillNeg)? " neg" : " ");
> printf("vnum = %ld %s\n", vtest, (vstillNeg)? " neg" : "");
> num += 1; vnum += 1;
> }
> return 0;
> }
--
Ben.
==============================================================================
TOPIC: Efficency and the standard library
http://groups.google.com/group/comp.lang.c/t/ad9fea19f2f7dd61?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 6:05 am
From: ImpalerCore
On Mar 11, 3:15 am, "io_x" <a...@b.c.invalid> wrote:
> "spinoza1111" <spinoza1...@yahoo.com> ha scritto nel messaggionews:25c6d801-b2f9-4c79-8227-f5df27a69876@s25g2000prd.googlegroups.com...
> On Feb 13, 5:25 pm, spinoza1111 <spinoza1...@yahoo.com> wrote:
> #io_x
> ...latest code...
>
> <snip>
>
> In view of the face that NO OTHER POSTER (to my knowledge) has met the
> requirements (code a string replace function without string.h usage) I
> hereby declare victory, and award myself the Golden Spinoza Order of
> Purity and Truth har har.
>
> Seriously, I have demonstrated, I believe, that Republicans can't code
> worth dick, but they can (if Peter Seebach is still a Republican) say
> "there is a bug in my code but I'm fucked if I'll fix it", and they
> sure can backstab and lie. That is: there is an entire programming
> world-view, a Gestalt, that is complete malarkey and normalized
> deviance. It consists of the inchoate saws and maxims that have
> accumulated over time, that have sifted down from on-high from capable
> early developers, but which have become little more than a cargo
> cult.
>
> My code is hard to read, it is said (on dit). In a sense, it is. I
> find it hard to read at times myself.
>
> #i find hard my code only at first see
> #but if i think about it, i find it readable and easy
> #
> #if my code is hard it is because do complex things.
> #if i have one problem is how to traslate one complex problem
> #to his little one problems, but now i think not have it too
>
> An entire story exists in the cargo cult of the programmer who is in
> some versions of the story "too clever by half" and in others only
> thinks he is, and who writes an enormous program that nobody can
> figure out.
>
> #people not understand because someone has experience of some language
> #some routines, that other people not have
>
> The social function of the story is to normalize
> differences in ability, and to cover up the fact that many companies
> try to solve ill-defined and very hard problems with computers, often
> in order to exploit their workers or cheat customers. It omits the
> existence of real code written by ordinary members of the white collar
> proletariat which solved in an unsung fashion a hard problem...such as
> the assembler for the 8K IBM 1401 that was written by a Univ of Chi
> graduate student that put the IBM assembler to shame.
>
> When looking for work in the 1990s, I answered an ad from Rockwell-
> Wescom, a telecom manufacturer in Chicago. During my interview, the
> manager said "some guy many years ago figured out how to use our call
> data to reconstruct calls by simulating the PBX: he was pretty
> strange." I said, "that was me". I'd become a legend of the dreamtime.
> I didn't get a job because, the manager said, I was "too good to be
> true". There had to be something wrong with a guy who'd solved a
> problem nobody else could solve but was looking for work in his
> forties.
>
> Whereas at a shipping conference in 2003 I was greeted with
> recognition by the staff of a shipbuilding firm for whom I'd created a
> key program in the 1980s. This was because their culture was one of
> openness and trust, not myth, and it's important that at the
> conference, they said that they weren't bothering to bid for work in
> Iraq. It was an ethical firm, of the sort that is in my experience
> rare.
>
> Code in some instance might look challenging because the problem is
> actually a bit hard.
>
> #and so the code for that problem could be hard
>
> Likewise it was hard for NASA engineers to solve
> the problem of O-ring temperatures in cold temperatures in the
> Challenger space shuttle, and later for them to solve the problem of
> foam insulation dropping off Columbia at launch.
>
> "They say it couldn't be done. So, I didn't do it."
>
> In a post-Enlightenment culture of real science that has sifted down
> to low-level technicians distinguished only by their conformity,
> passive-aggression, frightened political conservatism (or passive-
> aggressive "libertarianism") and/or religious Fundamentalism, the
>
> #yes possible i'm fundamentalist, when i convince myself of something
> #it is not easy change idea for what say other when no code is show
>
> former science (including Dijkstra's misinterpreted admonitions
> concerning simplicity and "the humble programmer") become a cargo cult
> of excuses for normalized deviance.
>
> #to program, some time, is not easy and one has to be humble always
> #because exist always that 90% that is better of me
> #and each one has his/her way for write and for resolve problems
> #and that way of resolve can not be simulated in another one people
>
> In a recent collection of writings on popular music by my fat pal
> Theodore Adorno, he sets out the contrast starkly between classical
> and popular music, and this is applicable to programming.
>
> Popular music, he wrote, seems free and liberating, but in actuality
> is almost always oversimplified in structure (and this is still true
> of pop music years after he wrote it). The dissonances and syncopation
> rely for their effect, he wrote, on the fact that for the listener
> they are not actual artistic and standalone statements, but instead
> sardonic POINTERS (references) back to classical music, light
> classical music, and more traditional pop music.
>
> The pop composer, even Irving Berlin or Copland, relies for his effect
> on a backreference which says inside the music "listen, I flatted that
> note, but you can if you like normalize my deviance by treating what I
> said as unserious".
>
> Consider the difference between Phillip Glass or Ygor Stravinsky on
> the one hand, and Alban Berg on the other. The audience, according to
> a 1980s Time magazine article about Glass, happily "sighed" when
> Glass's cheap backreferences to the most innocuous classical music
> with an easy-listening rock beat started to drone. Likewise, the
> anxious bourgeois applauded Stravinsky (and Picasso) in the 1920s when
> they reverted to classical models by means of snarky backreferences
> with just enough dissonance to make the audience feel hip.
>
> Whereas Beethoven meant to write the entire symphony in such a way
> that ANY change would damage the whole (whereas my formatting and
> naming conventions are not something I can willingly discard). (I
> really felt for Tom Hulce's Amadeus in the eponymous movie when he was
> told to discard notes by the Emperor).
> <snip>
Looks like you've become addicted to spinoza's drug and are having
withdrawals. Remember, just say no. Don't worry, your side effects
will disappear eventually and you can live to become a normal clc
poster again.
==============================================================================
TOPIC: question about macro?
http://groups.google.com/group/comp.lang.c/t/78ed6f536b032cfc?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 6:05 am
From: Ben Bacarisse
Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> Ian Collins <ian-news@hotmail.com> writes:
>>> MBALOVER wrote:
>>>> Hi all,
>>>>
>>>> Actually I want my code to be
>>>>
>>>> for (i=0;i<N;i++)
>>>> {
>>>> array2[i*30]=array1[i];
>>>> ..................
>>>> array2[i*30+29]=array1[i];
>>>> }
>>>>
>>>> If there anyway to use macros to do it instead for listing out
>>>> manually in the code like above?
>>>
>>> Forget macros, they won't help here.
>>>
>>> How about memset?
>
> On many installations, you'll find that's a macro! ;-)
>
>>> (untested)
>>>
>>> memset( array2+i*30, array1[i], 30*sizeof(array2[0]) );
>>
>> As Keith has pointed out memset won't do. memcpy, on the other hand,
>> can do it in 5 calls:
>>
>> array2[i+30] = array1[i];
>> memcpy(array2+i*30 + 1, array2[i+30], sizeof array2[i]);
>> memcpy(array2+i*30 + 2, array2[i+30], 2 * sizeof array2[i]);
>> memcpy(array2+i*30 + 4, array2[i+30], 4 * sizeof array2[i]);
>> memcpy(array2+i*30 + 8, array2[i+30], 8 * sizeof array2[i]);
>> memcpy(array2+i*30 + 16, array2[i+30], 14 * sizeof array2[i]);
>>
>> Note the final multiplier (if I've go it right).
>
> 14's right. The +30's should be *30's.
Of course. Thanks.
> I timed this against a naive loop for int, long long, and
> double types. Conclusions were inconclusive. For double,
> the naive loop was faster when compiled for plain i386, but
> slower when 'optimised' for the actual athlon-xp architecture.
> For int and long long, the memcpys were faster than the loop.
> The memcpys were in fact simply unrolled completely.
Was this for the *30 example or the latter *1000 example?
> Given that there was a case where the memcpys were measurably
> slower, it's not worth blindly going for the clever technique
> until you've both found that the naive loop is slowing you down
> and measured the two to make sure that the optimisation is in
> fact an improvement. Writing a clever version for speed without
> measuring whether it's faster or not is dumb. And frequently
> done, alas.
The measuring is important but you can't find out that it is not
always faster without writing it! Having written it, I'd be tempted
to keep it around in some sort of conditional compilation so that it
can be switched in when/if measurements show that it is better on some
architecture/implementation.
One does ave to weight the maintenance cost, so there must be at least
the possibility of a benefit.
--
Ben.
==============================================================================
TOPIC: Best way/library to draw individual pixels on screen? <OT>
http://groups.google.com/group/comp.lang.c/t/bf4e0288d8537985?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 6:29 am
From: Andrew Poelstra
On 2010-03-11, Robbie Hatley <see.my.signature@for.my.contact.info> wrote:
>
> "Andrew Poelstra" wrote:
>
>>
>> See http://www.yosefk.com/c++fqa
>>
>> for a critique from somebody quite passionate about this issue.
>
> Yossi Kreinin is "passionate", all right, but if you read in depth,
> You'll see that he doesn't just criticize C++, but says it's
> good for nothing, and the wrong choice for EVERY use. He uses
> the words "shitty" and "crappy" a lot on his web site in
> reference to C++. I get the impression that C++ is just too much
> language for him to handle.
>
This is true. It's unfortunate that he comes off as such a
kook, because he raises some valid points (for example,
the problems with memory management and exceptions, or the
inherent "publicization" of private members.)
> This is especially evidenced by the fact that he slams C++ for
> presenting so many alternate ways of doing things, especially
> for having both C features (such as arrays) and C++ features
> (such as std::vector). But I think that's one of the BEST points
> of C++, not the worst; it gives the programmer the option of
> either doing things "close to the machine" (such as by using
> arrays, or malloc/free), or doing things at a higher level of
> abstraction (such as with std::vector, or new/delete). For
> a programmer who lacks conciousness of abstraction, this
> plethora of choices would seem daunting. As it apparently does
> to Yossi Kreinin.
>
--
Andrew Poelstra
http://www.wpsoftware.net/andrew
==============================================================================
TOPIC: Cheap Wholesale A&F Shirt, Armani Shirt, Christan Audigier Coat, Bape
Coat, Scarf etc free shipping (www.vipchinatrade.com)
http://groups.google.com/group/comp.lang.c/t/1700bdaceaed6ee9?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 7:09 am
From: yoyo
Shirt
Cheap Wholesale A&F Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale Armani Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale BOSS Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale Burberry Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale D&G Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale Gucci Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale Lacoste Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale Paul Shirt <www.vipchinatrade.com paypal payment>
Cheap Wholesale Tommy Shirt <www.vipchinatrade.com paypal payment>
Coat
Cheap Wholesale 10DEEP Coat (wholesale free shipping)
Cheap Wholesale 999 Coat
Cheap Wholesale A Coat (wholesale free shipping)
Cheap Wholesale Adidas Coat
Cheap Wholesale Bape Coat <www.vipchinatrade.com paypal payment>
Cheap Wholesale BBC Coat
Cheap Wholesale Christan Audigier Coat
Cheap Wholesale Coogi Coat
Cheap Wholesale ED Hardy Coat (wholesale free shipping)
Cheap Wholesale Evisu Coat
Cheap Wholesale Gndigo Coat <www.vipchinatrade.com paypal payment>
Cheap Wholesale Gucci Coat
Cheap Wholesale KA Coat (wholesale free shipping)
Cheap Wholesale Lacoste Coat <www.vipchinatrade.com paypal payment>
Cheap Wholesale LRG Coat
Cheap Wholesale Parish Coat <www.vipchinatrade.com paypal payment>
Cheap Wholesale Pjmark Coat
Cheap Wholesale POLO Coat
Cheap Wholesale Rogawpar Coat
Cheap Wholesale Sean And Joh Coat <www.vipchinatrade.com paypal
payment>
Scarf
Armani Scarf (wholesale free shipping)
Burberry Scarf<www.vipchinatrade.com paypal payment>
Chanel Scarf <www.vipchinatrade.com paypal payment>
CK Scarf (wholesale free shipping)
D&G Scarf<www.vipchinatrade.com paypal payment>
Dior Scarf <www.vipchinatrade.com paypal payment>
Fendi Scarf <www.vipchinatrade.com paypal payment>
Gucci Scarf<www.vipchinatrade.com paypal payment>
LV Scarf <www.vipchinatrade.com paypal payment>
Paul Smith Scarf<www.vipchinatrade.com paypal payment>
Tous Scarf<www.vipchinatrade.com paypal payment>
Sweaters
ED Hardy Sweaters<www.vipchinatrade.com paypal payment>
==============================================================================
TOPIC: Stylistic questions on UNIX C coding.
http://groups.google.com/group/comp.lang.c/t/51d2b24a60d73f18?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Mar 11 2010 7:35 am
From: BruceS
On Mar 10, 1:29 pm, Anand Hariharan <mailto.anand.hariha...@gmail.com>
wrote:
> On Mar 4, 8:40 am, Richard <rgrd...@gmail.com> wrote:
> (...)
>
> > You dont say "if pi is larger than p".You say "if p is larger than
> > pi".
>
> They are not equivalent statements. ;-)
No, they certainly aren't (good catch)! If one writes code with the
assumption that these are the same, one introduces a bug. So, a
better question might be which of the following would you say:
"e is larger than pi"
"pi is larger than e"
?
I know which *I* prefer.
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c?hl=en
To unsubscribe from this group, send email to comp.lang.c+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home