I haven’t tried this, but I wonder if the fact that it is “main” has
anything to do with the lack of warning, due to main being able to have
at least three possible valid definitions. Also, of course, this whole
issue depends entirely on how one builds this code (-w), and potentially
#pragmas buried somewhere.
As far as goto, I basically agree with Tim here, with the addition that
ease of understanding and ease of debugging are sometimes at odds with
each other with regards to returning control paths. In particular,
related to the goto issue it is sometimes said that there should be only
one “return” in a function. This is, ignoring optimizations, easier to
debug, but, in my opinion, the nested “if” mess that following the rule
can create in many cases is not by a long shot easier to understand than
multiple returns. I think the case can be made (as the author of NT
File System Internals does) for goto in some cases, although I am not a
disciple of that school of thought. Also, although I am a frequent use
of both SEH and C++ EH, I personally find statements to the effect that
these are show how “simpler” than basically any other form of flow
control patently absurd. They are obfuscating. I still find them worth
it overall, because they are cleaner, but they are certainly no
panacea.
mm
>> xxxxx@sintefex.com 2007-05-17 04:51 >>>
Surely the only important issue here is (as Maxim said) that any
complier
should issue an error that not all control paths return a value. Any
that
don’t have not parsed it correctly.
Since the source code is invalid C the results if it does (appear to)
compile must be garbage.
I think we all find complier anomalies from time to time, presumably
most
people, like me, find a workaround and move on. Reporting it to the
supplier
is more public spirited, but we seldom have time.
BTW I thought goto was a valid part of the language. Most of us were
taught
that a good rule of thumb is to avoid them as there is often a better
architecture. These rules are of course for the the guidance of the
wise
(and the obediance of ??? - I can’t remember the original quote…).
Mike
----- Original Message -----
From: raj_r
To: Windows System Software Devs Interest List
Sent: Thursday, May 17, 2007 9:08 AM
Subject: Re: [ntdev] Strange problem with VC++ compiler because of
goto
well not hoping to turn this thread into a you you me me flame war
but gotos do have thier use and i ve seen some very good code being
being emitted when using gotos
and being constantly fed wtih propaganda against using gotos i asked
someone
about the phenomena
i have a the best possible code emitted by the compiler when i am using
goto
in my c source (no embedded jumps inserted but compiler was clever
enough to seamlessly merge the code into a single proc with goto)
but it seems every tom dick and harry and his poodle out there is
fanatic about me not using goto
and he replied something in this vein
using goto is like dividing by zero
in school mathematics dividing by zero is impossible cannot be done
in highschool mathematics you get the tone of dividing by zero is
acceptable with certain caveats
when you are doing college mathematics
you can certainly divide by zero and derive a result that tends to some
limit
not sure the analogy fits in or not but i do believe in some cases
gotos have the best possible outcome of compiled code
no flames please
On 5/17/07, Edouard A. wrote:
> To avoid this problem the best is to have strict guidelines about
that
> kind
> of stuff within your team(s). When new people come into the team they
are
> made aware of the rules, which are:
>
> 1/You do not talk about GOTO
> 2/You DO NOT talk about GOTO
>
> –
>
> EA
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com [mailto:bounce-286997-
> > xxxxx@lists.osr.com] On Behalf Of Robert Kennett
> > Sent: jeudi 17 mai 2007 09:06
> > To: Windows System Software Devs Interest List
> > Subject: Re: [ntdev] Strange problem with VC++ compiler because of
goto
> >
> > I find that goto’s are one of the most singularly useful
constructs
> > there is. Just one or two, placed at strategic points in the code,
will
> > derail any serious code review while the participant flame each
other
> > into fits and ignoring the substance of the code. Goto’s also work
> > great
> > for turning ntdev into slashdot. Any thoughts on genetically
altered
> > corn?
> >
> >
> >
> > > I don’t mean the snap but.
> > >
> > >
> > >
> > > You shouldn’t use gotos. Avoid them. In a world of exceptions
and
> > > encapsulated init/deinit there is no need for gotos. I recently
saw a
> > > code with gotos INSIDE a loop that went UP and since that minute
I
> > > decided that my tolerance toward gotos ended.
> > >
> > >
> > >
> > > –
> > >
> > > EA
> > >
> > > From: xxxxx@lists.osr.com
> > > [mailto:xxxxx@lists.osr.com] *On Behalf Of Raja
Reddy
> > > Sent: jeudi 17 mai 2007 06:44
> > > To: Windows System Software Devs Interest List
> > > Subject: [ntdev] Strange problem with VC++ compiler because of
goto
> > >
> > > Hello,
> > >
> > > Today I found a serious problem in the following code when I
compiled
> > > with VC++ 6.
> > >
> > > The installed compiler & linker versions are 12.00.8804,
6.00.8447 on
> > > x86 system respectively.
> > >
> > > #include <stdio.h>
> > >
> > > int alloc()
> > > {
> > > return 0;
> > > }
> > >
> > > int main(int argc, char argv)
> > > {
> > > printf(“Testing!\n”);
> > >
> > > if(alloc() == 0)
> > > goto Radhe;
> > >
> > > return 0;
> > >
> > > Radhe:
> > >
> > > printf(“Hello\n”);
> > >
> > > }
> > >
> > > I expected that “Hello” will be printed just once because, the
if
> > > statement jumps the instruction pointer to the label.
> > >
> > > But “Hello” is priting always till I kill the process.
> > >
> > > When I check the assembly code, I found a JMP instruction right
after
> > > printf(“Hello\n”) line, instead of a RET instruction.
> > >
> > > I don’t know whether this is known bug in VC compilers or
microsoft
> > > standard. I just want to share this with all of experts here.
> > >
> > > If this is the wrong place to post, please ignore.
> > >
> > > Regards,
> > >
> > > Raja Reddy.
> > >
> > >
---------------------------------------------------------------------
> > —
> > >
> > > Park yourself in front of a world of choices in alternative
vehicles.
> > > Visit the Yahoo! Auto Green Center.
> > >
> >
http:> >
_ylc=X3oDMTE5cDF2bXZzBF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDZ3JlZW4tY2
> > VudGVy>
> > > — Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit
the
> > > List Server section of OSR Online at
> > > http://www.osronline.com/page.cfm?name=ListServer
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > To unsubscribe, visit the List Server section of OSR Online at
> > > http://www.osronline.com/page.cfm?name=ListServer
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer</http:></stdio.h>