if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.
I dont want to debug GCC now. But just that, need some braces to get
across it . 16 2077 pa********@hotmail.com wrote:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.
I dont want to debug GCC now. But just that, need some braces to get
across it .
second
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32 pa********@hotmail.com wrote:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.
If you want to ask a question, it would be good to phrase your posting
as a question.
I assume your question is "which 'if' will the 'else' in the code above
correspond to?"
The 'else' will relate to the second 'if' so my reading of the code
could be expressed with indentation and braces as this :-
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK)) {
if (reason) {
*reason = "Object is a scope";
} else if (reason) {
*reason = "object is not writable";
}
}
which is clearly not a useful piece of code.
I think your intent would be expressed as :-
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK)) {
if (reason) {
*reason = "Object is a scope";
}
} else {
if (reason) {
*reason = "object is not writable";
}
}
Some of the braces could, naturally, be removed...
On 3 Oct, 16:22, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.
I dont want to debug GCC now. But just that, need some braces to get
across it .
This is an excellent example of why conditional statements without
braces are evil. As a maintenance programmer myself I would certainly
throw the above code back to the author at code review time. Run the
code through indent or similar, and you'll immediately see how the
compiler will parse it.
Run the code through indent
What is the meaning of that ?
@others
Thanks for the replies. It helped.
@Mark
Your second answer was my original intent. Thanks for that. It is
pretty much same for all compilers . Is it?
Like Java and other languages.
-Parag
<pa********@hotmail.comschrieb im Newsbeitrag
news:11**********************@w3g2000hsg.googlegro ups.com...
>Run the code through indent
What is the meaning of that ?
A tool that formats code, by identing it properly.
Bye, Jojo pa********@hotmail.com wrote:
>Run the code through indent
What is the meaning of that ?
It is widely used and powerful C source formatting tool. See below:
<http://www.gnu.org/software/indent/>
<http://en.wikipedia.org/wiki/Indent_%28Unix%29>
<http://www.linuxmanpages.com/man1/indent.1.php>
<snip>
"Joachim Schmitz" <no*********@schmitz-digital.deschrieb im Newsbeitrag
news:fe**********@online.de...
<pa********@hotmail.comschrieb im Newsbeitrag
news:11**********************@w3g2000hsg.googlegro ups.com...
>>Run the code through indent
What is the meaning of that ?
A tool that formats code, by identing it properly.
s/identing/indenting/
On Oct 3, 6:09 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
Run the code through indent
What is the meaning of that ?
indent is a common Unix application which does automatic
indentation of a C programme. I would imagine it also
exists for other platforms.
@Mark
Your second answer was my original intent. Thanks for that. It is
pretty much same for all compilers . Is it?
It would have been nice if you had actually quoted this
"second answer". I assume you mean the following piece of
code by Mark Bluemel:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
{
if (reason) {
*reason = "Object is a scope";
}
} else {
if (reason) {
*reason = "object is not writable";
}
}
And yes it is the same for every compiler which conforms
to the C standard. pa********@hotmail.com wrote:
) @Mark
) Your second answer was my original intent. Thanks for that. It is
) pretty much same for all compilers . Is it?
Required by the standard, AFAIK.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
On Oct 4, 3:33 am, ke...@bytebrothers.co.uk wrote:
I have a book called "The Bytes Brothers", is your
email address anything to do with that?
On 3 Oct, 16:22, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
This is an excellent example of why conditional statements without
braces are evil.
Not really, it is an example of bad indentation being evil. Cf:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason)
*reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
In fact, even better than both ideas is:
if ( reason )
{
if ( type == vhpiCompInstStmtK || type == vhpiRootInstK )
*reason = "Object is a scope";
else
*reason = "object is not writable";
}
On Wed, 03 Oct 2007 15:11:39 -0700, Old Wolf <ol*****@inspire.net.nz>
wrote:
>On Oct 4, 3:33 am, ke...@bytebrothers.co.uk wrote:
I have a book called "The Bytes Brothers", is your email address anything to do with that?
>On 3 Oct, 16:22, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
This is an excellent example of why conditional statements without braces are evil.
Not really, it is an example of bad indentation being evil. Cf:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason)
*reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
In fact, even better than both ideas is:
if ( reason )
{
if ( type == vhpiCompInstStmtK || type == vhpiRootInstK )
*reason = "Object is a scope";
else
*reason = "object is not writable";
}
But the braces are only necessary if you heed keith's advice (to whom
you responded), right?
Better yet is:
if ( reason )
{
if ( (type == vhpiCompInstStmtK) || (type == vhpiRootInstK) )
{
/* do something */
}
else
{
/* do something else */
}
}
Consistency is an important aspect of quality software. Whether it's
consistently good or bad is an entirely different matter.
I think you and keith are both right. You are welcome to apply to work
for me anytime :^)
Both unconditional use of braces, as keith purported, and proper
indentation, as you purported, should be specified in a properly
formed coding standard. Both of these rules are primarily intended to
reduce and ideally eliminate the probability that the "maintenance"
person will screw up the software with his or her changes.
In a desktop "Paint" program this may seem like a trivial pursuit, but
in the world of safety critical software, such conventions or
practices or standards go a real, real long way towards achieving high
quality software. You can bet your life on it, if you're so inclined.
And maybe--just maybe--what's good for safety critical software is
also good for the desktop "Paint" program. Based on my experience, I'd
bet my life on that.
Best regards,
--
Jay
[Discussion of which "if" an "else" will match with]
On 3 Oct, 18:09, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
@Mark
Your second answer was my original intent. Thanks for that. It is
pretty much same for all compilers . Is it?
Like Java and other languages.
Well, it's off topic here, but BCPL (a predecessor of C) got round the
problem by using "TEST" if there was an ELSE, and "IF" otherwise, so
you would have either:
IF expression THEN command1
or
TEST expression THEN command1 ELSE command2
Paul.
@Mark
Your second answer was my original intent. Thanks for that. It is
pretty much same for all compilers . Is it?
Like Java and other languages.
Well, it's off topic here, but BCPL (a predecessor of C) got round the
problem by using "TEST" if there was an ELSE, and "IF" otherwise, so
you would have either:
IF expression THEN command1
or
TEST expression THEN command1 ELSE command2
Paul.
Well, Paul,
But does TEST work this way,
TEST expression THE command1 ELSE TEST expression2 THEN command2 ELSE
command3
On Wed, 03 Oct 2007 15:11:39 -0700, Old Wolf wrote:
On Oct 4, 3:33 am, ke...@bytebrothers.co.uk wrote:
>This is an excellent example of why conditional statements without braces are evil.
Not really, it is an example of bad indentation being evil. Cf:
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason)
*reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
....which will immediately show that the code is wrong. The last if
branch will never be executed (unless reason is volatile, and is
being written from somewhere else in the time between the two
evaluation. But it's much more likely the programmer intended the
else to refer to the first if).
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.
On Wed, 03 Oct 2007 23:03:48 -0700, jaysome <ja*****@hotmail.com>
wrote:
<snip>
Both unconditional use of braces, as keith purported, and proper
indentation, as you purported, should be specified in a properly
formed coding standard. Both of these rules are primarily intended to
reduce and ideally eliminate the probability that the "maintenance"
person will screw up the software with his or her changes.
And increase the probability that other readers, like reviewers and
auditors, have the correct understanding they need.
In a desktop "Paint" program this may seem like a trivial pursuit, but
in the world of safety critical software, such conventions or
practices or standards go a real, real long way towards achieving high
quality software. You can bet your life on it, if you're so inclined.
But I have to disagree with this. Style rules like this do help move
you in the right direction, and are worth it for that reason; but they
do not by themselves get you anywhere near the destination -- and the
delusion that they do is itself a serious perhaps greater danger.
- formerly david.thompson1 || achar(64) || worldnet.att.net
[comp.lang.c] David Thompson <da************@verizon.netwrote:
But I have to disagree with this. Style rules like this do help move
you in the right direction, and are worth it for that reason; but they
do not by themselves get you anywhere near the destination -- and the
delusion that they do is itself a serious perhaps greater danger.
I think I agree with that statement, assuming that you mean to point
out that
if( gets() != NULL )
/* do something */
and
if( gets() != NULL ) {
/* do something */
}
are equally wrong. Good style is probably necessary, but not
sufficient, for achieving software nirvana.
--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: burn_hall |
last post by:
Hi,
I have a problem and can't figure it out and need your help, please
look at the following code and the output also a xml file snippet is
down there too.
Looking at the output I don't know why...
|
by: Naren |
last post by:
I have an XML like the one below.
I am using SAX parsing and I need to get the information between the
tags of the Email element. First i try to access the content and print
it out and it gives...
|
by: JackO |
last post by:
I have a text box on a form “txtExamDate” that I know contains nothing. I am
trying to test code that will determine the text box is nothing. I am
getting the error because there is no value...
|
by: Lalatendu Das |
last post by:
Dear friends,
I am getting a problem in the code while interacting with a nested
Do-while loop
It is skipping a scanf () function which it should not. I have written
the whole code below. Please...
|
by: Klaus Alexander Seistrup |
last post by:
Hi group,
I am new to xgawk (and seemingly to xml also), and I've been struggling
all afternoon to have xgawk parsing an XHTML file containing a hCard,
without luck. I wonder if you guys...
|
by: bluesteel |
last post by:
I wanted to know whether it was possible to write a while where the condition was checked in every instruction and stopped if false, i mean:
Considering the following coda:
condition
instruction...
|
by: Ramon F Herrera |
last post by:
http://groups.google.com/group/comp.lang.c/browse_frm/thread/86a3ddf0724d9630/4e38340aa824bee0?lnk=gst&q=how+to+best+parse+a+CSV&rnum=1#4e38340aa824bee0
http://tinyurl.com/29q4kf
Michael & Paul...
|
by: why? |
last post by:
I've been having problem with the following code. It's supposed to
print the prime numbers between 10 and 100. But i'm not getting any
output, i.e. i guess the outer 'for' loop is being traversed...
|
by: Shankarjee Krishnamoorthi |
last post by:
Hi,
I am new to Python. I am trying to do the following
inp = open(my_file,'r')
for line in inp:
# Perform some operations with line
if condition something:
# Start re reading for that...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |