Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > problems with logic operations within loops

Reply
Thread Tools

problems with logic operations within loops

 
 
Ersek, Laszlo
Guest
Posts: n/a
 
      01-27-2010
In article <(E-Mail Removed)>, jaysome <(E-Mail Removed)> writes:

> WARN_BASE=-Wc,-Wall -Wc,-W
> WARN_BASE += -Wc,-Wno-unknown-pragmas
> WARN_BASE += -Wc,-Wpointer-arith
> WARN_BASE += -Wc,-Wshadow
> WARN_BASE += -Wc,-Wwrite-strings
> WARN=$(WARN_BASE)
> WARN += -Wc,-pedantic
> WARN += -Wc,-Wbad-function-cast
> WARN += -Wc,-Wcast-align
> WARN += -Wc,-Wcast-qual
> WARN += -Wc,-Wconversion
> WARN += -Wc,-Wformat-nonliteral
> WARN += -Wc,-Wmissing-declarations
> WARN += -Wc,-Wmissing-prototypes
> WARN += -Wc,-Wnested-externs
> WARN += -Wc,-Wstrict-prototypes
> WARN += -Wc,-Wundef
>
> The "pedantic" reader will notice that the "-Wall" option to gcc
> doesn't really get you "all" warnings, as you would rightfully expect.
> When using the "-Wall" option with gcc, think of it as something like
> "-Wmost" or "-Wmany". Go figure.


Interesting. I notice you don't pass -ansi or -std=c[89]9, even though
you pass -pedantic. Maybe you do this exactly in order to enable C++
style comments:

----v----
`-ansi'

[...] For the C compiler, it disables recognition of C++ style `//'
comments as well as the `inline' keyword.
----^----

I use -Wformat=2 instead of -Wformat-nonliteral, as the former includes
the latter and more. I also pass -Wfloat-equal -Wlarger-than-32767
-Wlong-long -Wredundant-decls -Wunreachable-code.

Cheers,
lacos
 
Reply With Quote
 
 
 
 
Michael Foukarakis
Guest
Posts: n/a
 
      01-27-2010
On Jan 27, 9:31*am, jaysome <(E-Mail Removed)> wrote:
> On Tue, 26 Jan 2010 17:02:58 +0000, Richard Heathfield
>
> <(E-Mail Removed)> wrote:
>
> [snip]
>
> >In other implementations, you have to invoke the compiler in a
> >non-conforming mode in order to use them.

>
> Wrong.
>
> I use // comments in C code and invoke the (gcc) compiler in a
> conforming mode. The trick to getting this to "work" is to pipe the
> output from the compiler into a script that weeds out the warning
> about "C++ style comments". The filter applied to the output of gcc is
> like this:
>
> grep -v 'warning:.*C\+\+ style comments'


Then one day, you might get introduced to -Werror (aka. The
Sledgehammer), or discover warnings that SHOULD'VE been errors
(especially if you're using someone else's code) and your "trick" will
give you so much grief.. Please send me a picture of your facial
expression then. TY.

> The "pedantic" reader will notice that the "-Wall" option to gcc
> doesn't really get you "all" warnings, as you would rightfully expect.
> When using the "-Wall" option with gcc, think of it as something like
> "-Wmost" or "-Wmany". Go figure.


No. Go RTFM. "Note that some warning flags are not implied by -Wall".
 
Reply With Quote
 
 
 
 
Joachim Schmitz
Guest
Posts: n/a
 
      01-27-2010
jacob navia wrote:
> Richard Heathfield a écrit :
>>
>> Yes. Most C compilers, however, are not C99 compilers.
>>

>
> This is yet another lie. Please name one compiler that doesn't
> accept // comments by default.


c89 on NonStop Kernel. And no, there is no c99 nor c95 available on that
platform.

There is, however, a switch to enable C++ style
comments, -Wallow_cpluplus_comments
There is also a switch -Wc99lite to ebable some, but by far not all c99
features.

> And no, putting gcc in pedantic mode doesn't count.
>
> This is standard C, and it is widely implemented. I bet you can't
> even name one compiler that doesn't accept those comments.


Bet lost.

Bye, Jojo

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      01-27-2010
Joachim Schmitz a écrit :
> jacob navia wrote:
>> Richard Heathfield a écrit :
>>>
>>> Yes. Most C compilers, however, are not C99 compilers.
>>>

>>
>> This is yet another lie. Please name one compiler that doesn't
>> accept // comments by default.

>
> c89 on NonStop Kernel. And no, there is no c99 nor c95 available on that
> platform.
>
> There is, however, a switch to enable C++ style comments,
> -Wallow_cpluplus_comments
> There is also a switch -Wc99lite to ebable some, but by far not all c99
> features.
>


Well, you see?

// comments are an universal feature in all C compilers, please let's stop
this stupidity. It is the most widely used C99 feature.

 
Reply With Quote
 
Antoninus Twink
Guest
Posts: n/a
 
      01-27-2010
On 27 Jan 2010 at 17:41, Richard Heathfield wrote:
> jacob navia wrote:
>> // comments are an universal feature in all C compilers,

>
> Clearly not. You have already been shown some examples.


Another lie to add to the tally, Heathfield.

Every single example presented so far has been of a compiler that
accepts // comments by default, but rejects them if you go out of your
way to provide options to run the compiler in a crippled mode with
certain features disabled.

>> please let's stop this stupidity.

>
> Be my guest.


Why is the real world such an unappealing place to you, Heathfield?

 
Reply With Quote
 
Antoninus Twink
Guest
Posts: n/a
 
      01-27-2010
On 26 Jan 2010 at 19:15, Nick wrote:
> Richard Heathfield <(E-Mail Removed)> writes:
>> No, in C99 you can use them - but only six people have a C99
>> compiler.

>
> I do think you're being unnecessarily dogmatic, and confusing for
> newcomers, here.


No ****, Sherlock.

> Firstly, in the case of just about every compiler I've come across, the
> question isn't one of "invoking in a non-conforming mode", it's a case
> of "not very carefully specifying half-a-dozen flags to force it into a
> conforming mode".


Exactly.

> Even if there are no C99 compilers, what the OP posted was perfectly
> good C99 as far as I can see (certainly it appeared to be perfectly good
> C with no features that worked differently between C standards, but with
> // comments).


Exactly.

> To claim you'd like to widen topicality, and then claim that any code
> with // comments in it is equivalent to Fortran seems a bit rich, IMO.


Exactly.

 
Reply With Quote
 
Paul N
Guest
Posts: n/a
 
      01-27-2010
On 26 Jan, 18:32, Richard Heathfield <(E-Mail Removed)> wrote:
> jacob navia wrote:
> > Richard Heathfield a écrit :

>
> > Please name one compiler that doesn't
> > accept // comments by default.

>
> Any compiler invoked in C90 conforming mode is required to issue a
> diagnostic message when translating a translation unit containing at
> least one syntax error or constraint violation. Since // comments are
> always a syntax error in C90 (pathological cases excepted), all
> C90-conforming compilers are required to object to // comments.
>
> > This is standard C, and it is widely implemented. I bet you can't
> > even name one compiler that doesn't accept those comments.

>
> If by "accept" you mean "fail to issue a diagnostic message for", then
> no C90-conforming implementations accept them. I will win the bet by
> naming Borland C.


I think most people would regard "Borland C accepts // comments in its
default mode" as being a proof, rather than a disproof, of the
statement "Borland C accepts // comments".
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      01-28-2010
Tim Streater <(E-Mail Removed)> writes:
> if (isspace(ch)==true) continue;


I don't remember seeing anyone jump on that line. isspace() returns
something which is either zero or non-zero. Do not pretend you can
guess what non-zero value it might have. (And cast not-unsigned
chars to unsigned char before passing them to it, of course.)

Phil
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      01-29-2010
On 2010-01-28, Phil Carmody <(E-Mail Removed)> wrote:
> Tim Streater <(E-Mail Removed)> writes:
>> if (isspace(ch)==true) continue;


> I don't remember seeing anyone jump on that line. isspace() returns
> something which is either zero or non-zero. Do not pretend you can
> guess what non-zero value it might have. (And cast not-unsigned
> chars to unsigned char before passing them to it, of course.)


Good catch.

Interestingly, you can safely do (in C99):
bool x = isspace(ch);
if (x == true) ...

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      01-29-2010
Seebs <(E-Mail Removed)> writes:

> Interestingly, you can safely do (in C99):
> bool x = isspace(ch);
> if (x == true) ...


Yes.

"bool" is tricky though. Suppose that you instead wrote this:

bool x = isspace(ch);
if (x) ...

This will always do the right thing on C99. It usually works on
C89, too, if "bool" is a typedef to, say, unsigned char. But not
always: if isspace() returns 0x1000 for "true", and unsigned char
is an 8-bit type, then it will misclassify spaces as non-spaces.

So I always (if I'm thinking carefully) write assignments to bool
like this:

bool x = isspace(ch) != 0;
--
"For those who want to translate C to Pascal, it may be that a lobotomy
serves your needs better." --M. Ambuhl

"Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Logic Map/Logic Flow Chart. (Example Provided) spike Python 8 02-09-2010 12:31 PM
Asynchronous Logic Gates and Analog Logic Gates Jyoti Ballabh Software 3 11-26-2009 06:48 PM
Successive arithmetic operations within a process dennismccarty VHDL 1 03-15-2009 08:20 AM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
Loops with loops using html-template Me Perl Misc 2 01-12-2006 05:07 PM



Advertisments