debug vs release builds

>A pet peeve of mine is those who use the while(0) or even while(1) to end do

loops. The only legal K&R method of having an infinite loop construct is by
using for( ; ; ) {};

Correct on while(1), and, BTW, cl.exe warns on while(1)

make the break; the last statement before the closing bracket, it becomes a
while(0) terminator.

So what? while(0) is a part of do { } while(0) which is a block, and not a loop. This form is only used to require the semantic-less semicolon after this block.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

K&R C is dead, and what is legal or not legal in it is of no consequence.

The reason the K&R compilers favored for(;:wink: instead of while(TRUE) was the
compiler was so mind-bogglingly stupid that it wouldn’t optimize while(TRUE)
into an infinite loop; the code really was

test:
mov r0, 1
je exitloop
…loop
jmp test
exitloop:

So the for(;:wink: construct was used because of the hopeless inadequacy of the
compiler.

Any self-respecting compiler that sees

while(FALSE)
{
}
would generate the following code for the body of the loop:

which is what should happen. Basing design decisions on bad compilers for
obsolete languages is never a good strategy.

[I started programming in C in 1975 on the PDP-11, having spent much of my previous time using real optimizing compilers that actually generated good code. I was completely apalled at the code quality of the original K&R compiler]
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David Craig
Sent: Thursday, December 18, 2008 9:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] debug vs release builds

A pet peeve of mine is those who use the while(0) or even while(1) to end do
loops. The only legal K&R method of having an infinite loop construct is by
using for( ; ; ) {}; with a break statement where needed to get out. If you
make the break; the last statement before the closing bracket, it becomes a
while(0) terminator. It will not cause an error/warning with any compiler I
have seen or even the latest PC-Lint since K&R specifically states that the
three parts of the ‘for’ are optional.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> I thought do {} while (0); was to allow you to break out of a block of
> statements without using goto.

Not only.

do { … } while(0) is the usual way of writing the right-side of the
function-like macro, so that extra semicolon (which can inlfluence the
semantics) will not be added as expansion.

Actually, if you use #define to write an inline function, its body should be
wrapped by do { … } while(0)


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

As an *error*, sure, that sounds wrong, unless you are using -Wall. It is generally standard for that to be a warning, however.

? S

-----Original Message-----
From: Joseph M. Newcomer
Sent: Thursday, December 18, 2008 17:00
To: Windows System Software Devs Interest List
Subject: RE: Re:[ntdev] debug vs release builds

It was gcc. It thought that an empty statement was an error.

The diagnostic is based on faulty premises.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Skywing
Sent: Thursday, December 18, 2008 7:41 PM
To: Windows System Software Devs Interest List
Subject: RE: Re:[ntdev] debug vs release builds

Such as cl.exe or gcc…?

- S

-----Original Message-----
From: Joseph M. Newcomer
Sent: Thursday, December 18, 2008 15:47
To: Windows System Software Devs Interest List
Subject: RE: Re:[ntdev] debug vs release builds

Only really bad compilers or compilers with warnings written by people who
don’t know how to program.

I had one of these years ago. It also issued warnings if the if-test was
compile-time constant. It thought that {} was an error. I have no idea
what kind of person could think any of these were worthy of issuing a
warning. To me, empty statemens are a normal programming modality.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Skywing
Sent: Thursday, December 18, 2008 12:03 PM
To: Windows System Software Devs Interest List
Subject: RE: Re:[ntdev] debug vs release builds

Most compilers will issue a warning if they encounter an empty conditional
statement, however.

- S

-----Original Message-----
From: Cay Bremer
Sent: Thursday, December 18, 2008 04:33
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] debug vs release builds

Maybe there’s some paranoid warning level prohibiting them, but since empty
statements are valid C, there shouldn’t be a compiler error. I completely
agree about the use of the __noop intrinsic, though.

- Cay

On Thu, 18 Dec 2008 13:05:39 +0100, Pavel A. wrote:
> Ah, sorry, you’re right. This would be a compile error, not something
> in runtime.
>
> --PA
>
>
> Pavel A. wrote:
>> Cay Bremer wrote:
>>> Are you sure about this?
>>> Shouldn’t the semicolon after KdPrint() still constitute an empty
>>> statement?
>> A good catch.
>> The DDK KdPrint, KdPrintEx macros are defined just as NOTHING in
>> release build, thus leaving a room for this bug.
>> The modern MS compiler has__noop() intrinsic so we don’t need to
>> roll our own “do nothing”
>> statements like do{}while(0) etc.
>> So it should be now:
>> #define KdPrint(x) __noop()
>> (recently I’ve posted some examples in development.device.drivers
>> NG) Regards, --PA
>>
>>> On Thu, 18 Dec 2008 09:38:38 +0100, James Harper
>>> wrote:
>>>>> hello folks,
>>>>>
>>>>> what is the difference between debug and release mode builds. i
>>>>> have a driver that works fine in debug mode but fails in relesae
>>>>> mode, looks
>>>> like
>>>>> either data alignment error or some thing related to stale
>>>>> variables/ pointers.
>>>>>
>>>>> so what all are the differences b/w the two?
>>>>>
>>>>
>>>> One thing that has caught me out before is that this code:
>>>>
>>>> "
>>>> if (something == something_else)
>>>> KdPrint((“Something matches here\n”)); some_var = 12345; "
>>>>
>>>> compiles to this when debug is disabled:
>>>>
>>>> "
>>>> if (something == something_else)
>>>> some_var = 12345;
>>>> "
>>>>
>>>> because KdPrint is a no-op when debugging is off. If some_var is
>>>> otherwise un-initialised you’ll get a compiler warning, but
>>>> otherwise you’ll get nothing at all.
>>>>
>>>> You can see the problems that that would cause!
>>>>
>>>> James


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Personally, I think that do/while 1/0 would have been better to have been permitted by the standard. They are more explicit than for(;:wink: break; IMO, which is always good.

? S

-----Original Message-----
From: David Craig
Sent: Thursday, December 18, 2008 18:05
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] debug vs release builds

A pet peeve of mine is those who use the while(0) or even while(1) to end do
loops. The only legal K&R method of having an infinite loop construct is by
using for( ; ; ) {}; with a break statement where needed to get out. If you
make the break; the last statement before the closing bracket, it becomes a
while(0) terminator. It will not cause an error/warning with any compiler I
have seen or even the latest PC-Lint since K&R specifically states that the
three parts of the ‘for’ are optional.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> I thought do {} while (0); was to allow you to break out of a block of
> statements without using goto.

Not only.

do { … } while(0) is the usual way of writing the right-side of the
function-like macro, so that extra semicolon (which can inlfluence the
semantics) will not be added as expansion.

Actually, if you use #define to write an inline function, its body should be
wrapped by do { … } while(0)


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

K&R had no “standard”. It was just tradition, nothing more. “Legal” has no
meaning in this context. It was merely one person’s opinion about
programming style, and others either agreed or disagreed.

The ANSI/ISO standard would not say anything about while(TRUE) because this
is an issue of programming style, not an issue of standards. There is no
ambiguity of what while(TRUE) means. According to the standard, it means
that the loop body should be executed as long as the boolean condition
evaluates to non-zero. Which is always.

From Stroustrup, C++ Language, third edition:

The for-statement is also useful for expressing a loop without an explicit
termination condition:
for(;:wink: { // forever…\
// …
}

Page 136 [Emphasis: “is ALSO useful”. Not “is MANDATED”. Not “is THE ONLY
LEGAL WAY”.

From Harbison & Steele, “C: A Reference Manual, fourth edition” p.245

There are two common ways in C to write a loop that “never terminates”…

for(;:wink: statement
while(1) statement

Discussions of “legality” of these are nonsensical. You can argue style,
but not legality.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Skywing
Sent: Thursday, December 18, 2008 10:20 PM
To: Windows System Software Devs Interest List
Subject: RE: Re:[ntdev] debug vs release builds

Personally, I think that do/while 1/0 would have been better to have been
permitted by the standard. They are more explicit than for(;:wink: break; IMO,
which is always good.

  • S

-----Original Message-----
From: David Craig
Sent: Thursday, December 18, 2008 18:05
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] debug vs release builds

A pet peeve of mine is those who use the while(0) or even while(1) to end do
loops. The only legal K&R method of having an infinite loop construct is by
using for( ; ; ) {}; with a break statement where needed to get out. If you
make the break; the last statement before the closing bracket, it becomes a
while(0) terminator. It will not cause an error/warning with any compiler I
have seen or even the latest PC-Lint since K&R specifically states that the
three parts of the ‘for’ are optional.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> I thought do {} while (0); was to allow you to break out of a block of
> statements without using goto.

Not only.

do { … } while(0) is the usual way of writing the right-side of the
function-like macro, so that extra semicolon (which can inlfluence the
semantics) will not be added as expansion.

Actually, if you use #define to write an inline function, its body should be
wrapped by do { … } while(0)


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.

> K&R C is dead, and what is legal or not legal in it is of no consequence.

Since I am an ‘experienced’ developer I will add my $0.02 to this statement:
“Over my dead body”. I like K&R and still use my copy as a reference though
I don’t care for their brace placements. I know that anything I write using
K&R will compile with the compilers I have to use - Microsoft WDK and Visual
Studio. Microsoft doesn’t care about the ANSI C standard and doesn’t
support it. I would prefer to be able to define a loop control in the
initializer of a for statement, but it doesn’t work in my environment. We
write an in-box driver and stay with ‘C’ as Microsoft seems to prefer.

Also PC-Lint from Gimpel will flag all usage of do {} while(0/1/TRUE/FALSE).
It will also flag the while(1/TRUE) usage too.

I have programmed on the Honeywell 201, IBM ANFSQ7, Burroughs 3500/4700,
Sperry 1100/60, CP/M on Z80/8080, and various languages including assembly,
Pascal, Cobol, C, and C++ (maybe a few more, long ago forgotten). I do some
Python where indicated, but I generally try to avoid user mode.

I see your objection in that their choices were made because of the
limitations of compiler technology on the systems being used. It took
compiler vendors over a decade to get Ada fully working on many platforms.
However, my objections to ANSI C99 stands because the only vendor remaining
in my world just doesn’t support it.

“Joseph M. Newcomer” wrote in message
news:xxxxx@ntdev…
> K&R C is dead, and what is legal or not legal in it is of no consequence.
>
> The reason the K&R compilers favored for(;:wink: instead of while(TRUE) was
> the
> compiler was so mind-bogglingly stupid that it wouldn’t optimize
> while(TRUE)
> into an infinite loop; the code really was
>
> test:
> mov r0, 1
> je exitloop
> …loop
> jmp test
> exitloop:
>
> So the for(;:wink: construct was used because of the hopeless inadequacy of
> the
> compiler.
>
> Any self-respecting compiler that sees
>
> while(FALSE)
> {
> }
> would generate the following code for the body of the loop:
>
> which is what should happen. Basing design decisions on bad compilers for
> obsolete languages is never a good strategy.
>
> [I started programming in C in 1975 on the PDP-11, having spent much of my<br>&gt; previous time using real optimizing compilers that actually generated good<br>&gt; code. I was completely apalled at the code quality of the original K&amp;R<br>&gt; compiler]
> joe
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of David Craig
> Sent: Thursday, December 18, 2008 9:05 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] debug vs release builds
>
> A pet peeve of mine is those who use the while(0) or even while(1) to end
> do
> loops. The only legal K&R method of having an infinite loop construct is
> by
> using for( ; ; ) {}; with a break statement where needed to get out. If
> you
> make the break; the last statement before the closing bracket, it becomes
> a
> while(0) terminator. It will not cause an error/warning with any compiler
> I
> have seen or even the latest PC-Lint since K&R specifically states that
> the
> three parts of the ‘for’ are optional.
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntdev…
>> I thought do {} while (0); was to allow you to break out of a block of
>> statements without using goto.
>
> Not only.
>
> do { … } while(0) is the usual way of writing the right-side of the
> function-like macro, so that extra semicolon (which can inlfluence the
> semantics) will not be added as expansion.
>
> Actually, if you use #define to write an inline function, its body should
> be
> wrapped by do { … } while(0)
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>

You may be correct, but they weren’t. I don’t know about you, but K&R
didn’t consult me about their choices. Since they defined it that way and
the tools don’t like the other variations, I can live with it. Remembering
to place a break at the end sometimes can be a problem with the for loop,
but it does work and I don’t find it too objectionable. I just hope with
Win7 that Microsoft finally gets their headers so that they can be used with
W4 and PC-Lint without having to do so much work as previously required.

“Skywing” wrote in message
news:xxxxx@ntdev…
Personally, I think that do/while 1/0 would have been better to have been
permitted by the standard. They are more explicit than for(;:wink: break; IMO,
which is always good.

– S

-----Original Message-----
From: David Craig
Sent: Thursday, December 18, 2008 18:05
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] debug vs release builds

A pet peeve of mine is those who use the while(0) or even while(1) to end do
loops. The only legal K&R method of having an infinite loop construct is by
using for( ; ; ) {}; with a break statement where needed to get out. If you
make the break; the last statement before the closing bracket, it becomes a
while(0) terminator. It will not cause an error/warning with any compiler I
have seen or even the latest PC-Lint since K&R specifically states that the
three parts of the ‘for’ are optional.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> I thought do {} while (0); was to allow you to break out of a block of
> statements without using goto.

Not only.

do { … } while(0) is the usual way of writing the right-side of the
function-like macro, so that extra semicolon (which can inlfluence the
semantics) will not be added as expansion.

Actually, if you use #define to write an inline function, its body should be
wrapped by do { … } while(0)


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>> ASSERT( CallSomeAPI(…) ); <<

It is pretty easy to write code with side effects by mistake that will get
removed on release. The solution I find is to switch frequently backwards
and forwards between debug and release so any such errors (and other
volatility and timing errors) can be picked up as one goes along.

I had not heard of the __noop() C builtin function before. It is pity it
cannot take arbitrary arguments, e.g. __noop(…). Then the ASSERT above
could be replaced with __noop( CallSomeAPI(…) ) and this issue would fall
away as parameters could be evaluated and all the side-effects could still
happen. If only K&R had thought of it it might have been done better!

Maybe next time… M

Mike Kemp wrote:

>> ASSERT( CallSomeAPI(…) ); <<

It is pretty easy to write code with side effects by mistake that will
get removed on release. The solution I find is to switch frequently
backwards and forwards between debug and release so any such errors (and
other volatility and timing errors) can be picked up as one goes along.

I’m tempted to skip error handling when writing new code,
or just haven’t decided how to handle errors yet.
Specially for this, I got another macro that persists in free build,
it causes a breakpoint (= bugcheck).

I had not heard of the __noop() C builtin function before. It is pity it
cannot take arbitrary arguments, e.g. __noop(…).

It can! It actually is __noop(…) and your example below will work.

Regards,
– pa

Then the ASSERT above

could be replaced with __noop( CallSomeAPI(…) ) and this issue would
fall away as parameters could be evaluated and all the side-effects
could still happen. If only K&R had thought of it it might have been
done better!

Maybe next time… M

It also can be timing, if KdPrints/DbgPrints are used
on sensitive paths. DbgPrint(Ex) is quite heavy.
The OP hints to something like a sync issue (stale pointers…)

–PA

Maxim S. Shatskih wrote:

> what is the difference between debug and release mode builds.

DBG macro (which influences lots of stuff like KdPrint) and optimizations.

Look at the build log for details. How the compiler options differ?

> i have a driver that works fine in debug mode but fails in relesae mode, looks like either data
> alignment error or some thing related to stale variables/ pointers.

…or some thing related to DBG macro, or some thing related to compiler’s optimization bug - they are very early these days, but in the days of MSVC5 they were plenty.

Please tell us the details about the failure.

I avoid such problems by not writing expressions with side effects in the
first place. I consider them bad practice in terms of maintainability and
am hence strongly against them.

  • Cay

On Fri, 19 Dec 2008 10:15:15 +0100, Mike Kemp wrote:
>>> ASSERT( CallSomeAPI(…) ); <<
>
> It is pretty easy to write code with side effects by mistake that will
> get removed on release. The solution I find is to switch frequently
> backwards and forwards between debug and release so any such errors (and
> other volatility and timing errors) can be picked up as one goes along.
>
> I had not heard of the __noop() C builtin function before. It is pity it
> cannot take arbitrary arguments, e.g.__noop(…). Then the ASSERT above
> could be replaced with __noop( CallSomeAPI(…) ) and this issue would
> fall away as parameters could be evaluated and all the side-effects
> could still happen. If only K&R had thought of it it might have been
> done better!
>
> Maybe next time… M

Well, there are a few exceptions like the C for loop (although that’s
debatable), but they’re generally a bad sign regarding code quality, in my
opinion.

  • Cay

On Fri, 19 Dec 2008 11:54:38 +0100, Cay Bremer wrote:
> I avoid such problems by not writing expressions with side effects in
> the first place. I consider them bad practice in terms of
> maintainability and am hence strongly against them.
>
>
> - Cay
>
>
> On Fri, 19 Dec 2008 10:15:15 +0100, Mike Kemp wrote:
>>>> ASSERT( CallSomeAPI(…) ); <<
>>
>> It is pretty easy to write code with side effects by mistake that will
>> get removed on release. The solution I find is to switch frequently
>> backwards and forwards between debug and release so any such errors
>> (and other volatility and timing errors) can be picked up as one goes
>> along.
>>
>> I had not heard of the __noop() C builtin function before. It is pity
>> it cannot take arbitrary arguments, e.g.__noop(…). Then the ASSERT
>> above could be replaced with __noop( CallSomeAPI(…) ) and this issue
>> would fall away as parameters could be evaluated and all the
>> side-effects could still happen. If only K&R had thought of it it might
>> have been done better!
>>
>> Maybe next time… M

It is a Microsoft-specific extension. __noop() will silently eat all provided arguments (zero or more any). For example, it could replace a ‘printf’ style call without needing the usual double parens.

? S

-----Original Message-----
From: Mike Kemp
Sent: Friday, December 19, 2008 01:16
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] debug vs release builds

>> ASSERT( CallSomeAPI(…) ); <<

It is pretty easy to write code with side effects by mistake that will get
removed on release. The solution I find is to switch frequently backwards
and forwards between debug and release so any such errors (and other
volatility and timing errors) can be picked up as one goes along.

I had not heard of the __noop() C builtin function before. It is pity it
cannot take arbitrary arguments, e.g.__noop(…). Then the ASSERT above
could be replaced with __noop( CallSomeAPI(…) ) and this issue would fall
away as parameters could be evaluated and all the side-effects could still
happen. If only K&R had thought of it it might have been done better!

Maybe next time… M


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>>It is a Microsoft-specific extension. __noop() will silently eat all

>provided arguments (zero or more any). For example, it could replace a
>‘printf’ style call without needing the usual double parens.<<

Yeah, I read that it does it “without evaluating the arguments” so it will
remove any (mistakenly written) side-effects in release. That’s what I
thought was pity. As someone else said, we try not to write in side effects,
but it is an easy mistake ot make with C… M

Mike Kemp wrote:

>> It is a Microsoft-specific extension. __noop() will silently eat all
>> provided arguments (zero or more any). For example, it could replace
>> a ‘printf’ style call without needing the usual double parens.<<

Yeah, I read that it does it “without evaluating the arguments” so it
will remove any (mistakenly written) side-effects in release. That’s
what I thought was pity.

There is another one interesting thing.
Arguments of __noop() are still checked by the compiler, though it does
not produce code to evaluate them.

So, consider you wrote KdPrint((“foo=%x”, foo)) then changed to release
build and later removed the foo.
With today’s KdPrint, this will be unnoticed and your next checked build
will break.
If it were __noop(“foo=%x”, foo), missing foo will cause compiler error.

Regards,
–PA

Apologies for spamming in this thread.
–PA

As someone else said, we try not to write in

side effects, but it is an easy mistake ot make with C… M

Don’t try to play the “look how big mine is” game; there’s usually someone
whose list IS bigger than yours.

K&R was a bad book, incoherent for its time, and it never improved. Most of
us in the 1970s learned C in spite of it, rather than because of it. It
gave no formal specification of what things did, but worked mostly by
example.

This was good, because the language was so bad that you couldn’t actually
say what it would do in many circumstances.

I once worked for a company that had to produce a C compiler that was
bug-for-bug compatible with K&R C, that is, it couldn’t compile correct
code, it had to compile erroneous code so that existing programs would still
run because the programmers depended upon the erroneous behavior. I also
once worked for an organization that supported over 30 versions of Unix, and
we were constrained to write in SUBSET of K&R C because some compilers
wouldn’t compile the construct, or would compile it erroneously, or compile
it differently (because there were two or more ways to interpret what was
meant by the construct, and nobody could agree which one should be used).

Personally, I never really believed that a 30-year-old book that describes a
language implemention on a machine that no longer exists, and has not
existed for decades, is a valid approach to building software. Maybe this
is a bit weird, but I *like* the idea of type-checking prototypes, of
well-defined and agreed-upon semantics for not only the language but the
libraries, and so on.

What’s Ada got to do with anything? It took vendors longer than that to get
C working on multiple platforms. Most of them never succeeded, but went out
of business, abandoning their compilers and users. Having watched any
number of people have to transition from MIPS, Alpha, Apollo, and other
vendors, it is clear that none of those early compilers ever worked right.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David Craig
Sent: Friday, December 19, 2008 12:20 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] debug vs release builds

K&R C is dead, and what is legal or not legal in it is of no consequence.

Since I am an ‘experienced’ developer I will add my $0.02 to this statement:

“Over my dead body”. I like K&R and still use my copy as a reference though
I don’t care for their brace placements. I know that anything I write using
K&R will compile with the compilers I have to use - Microsoft WDK and Visual
Studio. Microsoft doesn’t care about the ANSI C standard and doesn’t
support it. I would prefer to be able to define a loop control in the
initializer of a for statement, but it doesn’t work in my environment. We
write an in-box driver and stay with ‘C’ as Microsoft seems to prefer.

Also PC-Lint from Gimpel will flag all usage of do {} while(0/1/TRUE/FALSE).

It will also flag the while(1/TRUE) usage too.

I have programmed on the Honeywell 201, IBM ANFSQ7, Burroughs 3500/4700,
Sperry 1100/60, CP/M on Z80/8080, and various languages including assembly,
Pascal, Cobol, C, and C++ (maybe a few more, long ago forgotten). I do some
Python where indicated, but I generally try to avoid user mode.

I see your objection in that their choices were made because of the
limitations of compiler technology on the systems being used. It took
compiler vendors over a decade to get Ada fully working on many platforms.
However, my objections to ANSI C99 stands because the only vendor remaining
in my world just doesn’t support it.

“Joseph M. Newcomer” wrote in message
news:xxxxx@ntdev…
> K&R C is dead, and what is legal or not legal in it is of no consequence.
>
> The reason the K&R compilers favored for(;:wink: instead of while(TRUE)
> was the compiler was so mind-bogglingly stupid that it wouldn’t
> optimize
> while(TRUE)
> into an infinite loop; the code really was
>
> test:
> mov r0, 1
> je exitloop
> …loop
> jmp test
> exitloop:
>
> So the for(;:wink: construct was used because of the hopeless inadequacy
> of the compiler.
>
> Any self-respecting compiler that sees
>
> while(FALSE)
> {
> }
> would generate the following code for the body of the loop:
>
> which is what should happen. Basing design decisions on bad compilers
> for obsolete languages is never a good strategy.
>
> [I started programming in C in 1975 on the PDP-11, having spent much <br>&gt; of my previous time using real optimizing compilers that actually <br>&gt; generated good code. I was completely apalled at the code quality of <br>&gt; the original K&amp;R compiler] joe
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of David Craig
> Sent: Thursday, December 18, 2008 9:05 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] debug vs release builds
>
> A pet peeve of mine is those who use the while(0) or even while(1) to
> end do loops. The only legal K&R method of having an infinite loop
> construct is by using for( ; ; ) {}; with a break statement where
> needed to get out. If you make the break; the last statement before
> the closing bracket, it becomes a
> while(0) terminator. It will not cause an error/warning with any
> compiler I have seen or even the latest PC-Lint since K&R specifically
> states that the three parts of the ‘for’ are optional.
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntdev…
>> I thought do {} while (0); was to allow you to break out of a block
>> of statements without using goto.
>
> Not only.
>
> do { … } while(0) is the usual way of writing the right-side of the
> function-like macro, so that extra semicolon (which can inlfluence the
> semantics) will not be added as expansion.
>
> Actually, if you use #define to write an inline function, its body
> should be wrapped by do { … } while(0)
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> This message has been scanned for viruses and dangerous content by
> MailScanner, and is believed to be clean.
>
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.

>I would prefer to be able to define a loop control in the

initializer of a for statement, but it doesn’t work in my environment.? We
write an in-box driver and stay with ‘C’ as Microsoft seems to prefer.

Just curious, what exactly doesn’t work in your environment? and how does it have anything to do with inbox driver. Could you give an example?

I had inboxed some drivers for massive production?chips such as graphics, network?from win9x, w2k to win7 and are working on some new inboxes on and off Redmond campus.?I am not aware of msft picking on how I write programs. They are reasonable. They have a lot of better things to do. As long as you have clean prefast/prefix log or you can explain why certain prefast/prefix warnings?are invalid or false positive, you’re fine.

Also PC-Lint from Gimpel will flag all usage of do {} while(0/1/TRUE/FALSE).
It will also flag the while(1/TRUE) usage too.

So what? Just shut it right?off the spot. do { } while (FALSE) is perfectly valid although I perfer if … goto… perhaps because I learned to use jc,jb,jgl jnc much earlier than I wrote my first C program.


Calvin Guan
Broadcom Corp.
Connecting Everything(r)?


Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com

David Craig wrote:

Since I am an ‘experienced’ developer I will add my $0.02 to this statement:
“Over my dead body”. I like K&R and still use my copy as a reference though
I don’t care for their brace placements. I know that anything I write using
K&R will compile with the compilers I have to use - Microsoft WDK and Visual
Studio. Microsoft doesn’t care about the ANSI C standard and doesn’t
support it.

For the C99 standard, that’s true. They certainly support the C89 standard.

I would prefer to be able to define a loop control in the
initializer of a for statement, but it doesn’t work in my environment. We
write an in-box driver and stay with ‘C’ as Microsoft seems to prefer.

You are aware that virtually every multimedia AVStream and BDA driver in
Windows, and most non-legacy audio drivers as well, are written in C++?
The “Microsoft prefers C” argument has some holes.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Yes, but that varies between which group/stack that your driver belongs.
There appears to be some movement at Microsoft to C++, but the paper on
doing C++ in drivers is still on the web site and I have heard at the DDC
that some are working with the compiler group to get more control over
placement of generated code. It is still not here yet. I have written many
drivers in C++, and do enjoy it however there are issues and when you are
part of a group that is geographically separated, it is more difficult.
Also, large legacy code bases make it harder to switch from one to the
other. Resource limitations are another issue. Many would prefer to be
able to do a complete rewrite with the current knowledge but that would take
a dedicated team apart from the group doing support for new chips and
maintenance. Not feasible in most companies in today’s market.

I have always been a guy who wants to try the new stuff and when doing a
project in C would want to get some coding time in assembly. That was true
in my Cobol days also. I just know how difficult it is to take, for
example, Windows and completely rewrite it from scratch doing a new design.
While our code is in no way that large, it is still significant. We also
provide our source code to our customers (OEMs) and I have heard they want
low risk and the product as quickly as possible. They have to get their
stuff to market quickly just as we do. We sell hardware not software.

Even Doran is rather cautious about recommending we folks out here use C++
in drivers everywhere even if parts of WDF are written in C++ (or so I have
heard). From the questions we see in these newsgroups it is easy to know
that the experience level for many of the people doing drivers is very
limited. I know that when I was hired, another position remained unfilled
and was canceled after more than a year of trying to find someone.

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> David Craig wrote:
>> Since I am an ‘experienced’ developer I will add my $0.02 to this
>> statement:
>> “Over my dead body”. I like K&R and still use my copy as a reference
>> though
>> I don’t care for their brace placements. I know that anything I write
>> using
>> K&R will compile with the compilers I have to use - Microsoft WDK and
>> Visual
>> Studio. Microsoft doesn’t care about the ANSI C standard and doesn’t
>> support it.
>
> For the C99 standard, that’s true. They certainly support the C89
> standard.
>
>> I would prefer to be able to define a loop control in the
>> initializer of a for statement, but it doesn’t work in my environment.
>> We
>> write an in-box driver and stay with ‘C’ as Microsoft seems to prefer.
>>
>
> You are aware that virtually every multimedia AVStream and BDA driver in
> Windows, and most non-legacy audio drivers as well, are written in C++?
> The “Microsoft prefers C” argument has some holes.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>

As you know we still use the 3790.1830 DDK for NDIS5 drivers. To make it
easier to maintain, most of the code is the same with the NDIS6 drivers as
it allows changes to be propagated easily to both. We still use an even
earlier DDK to support Windows 2000 and only recently have dropped new chip
support for NT4.

I have not asked, but didn’t hear anything at the DDC about NDIS support for
C++. One of the major tools, Static Driver Verifier, is adding support for
NDIS in Win7 but it will not work on C++ code. Maybe that will change with
Win8.

David Craig
Broadcom Corp.

“Calvin Guan” wrote in message news:xxxxx@ntdev…
>I would prefer to be able to define a loop control in the
>initializer of a for statement, but it doesn’t work in my environment. We
>write an in-box driver and stay with ‘C’ as Microsoft seems to prefer.

Just curious, what exactly doesn’t work in your environment? and how does it
have anything to do with inbox driver. Could you give an example?

I had inboxed some drivers for massive production chips such as graphics,
network from win9x, w2k to win7 and are working on some new inboxes on and
off Redmond campus. I am not aware of msft picking on how I write programs.
They are reasonable. They have a lot of better things to do. As long as you
have clean prefast/prefix log or you can explain why certain prefast/prefix
warnings are invalid or false positive, you’re fine.

>Also PC-Lint from Gimpel will flag all usage of do {}
>while(0/1/TRUE/FALSE).
>It will also flag the while(1/TRUE) usage too.

So what? Just shut it right off the spot. do { } while (FALSE) is perfectly
valid although I perfer if … goto… perhaps because I learned to use
jc,jb,jgl jnc much earlier than I wrote my first C program.


Calvin Guan
Broadcom Corp.
Connecting Everything(r)

__________________________________________________________________
Ask a question on any topic and get answers from real people. Go to Yahoo!
Answers and share what you know at http://ca.answers.yahoo.com