Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Definition of logical true in C++? (http://www.velocityreviews.com/forums/t586111-definition-of-logical-true-in-c.html)

Lars Uffmann 01-21-2008 07:06 AM

Definition of logical true in C++?
 
If I define a function, that shall return -1 in case of error, and a
positive value otherwise:

int foo (int param) {
if (outOfRange (param))
return -1;

return (param != 0);
}

can I rely on this code always working, or is it possible that the
return statement produces a -1 also, on a specific compiler / OS?
Is this defined somewhere? And if so, where in the standard?

Best Regards,

Lars

Sebastian Redl 01-21-2008 07:32 AM

Re: Definition of logical true in C++?
 
Lars Uffmann wrote:


> can I rely on this code always working, or is it possible that the
> return statement produces a -1 also, on a specific compiler / OS?
> Is this defined somewhere? And if so, where in the standard?


As defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.


--
Sebastian Redl

Lars Uffmann 01-21-2008 07:45 AM

Re: Definition of logical true in C++?
 
Sebastian Redl wrote:
> As defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.


Thanks, that's all I needed to know - though I just noticed that there's
no easily found online version of the C++ standards - are you able to
point me to one?

Best Regards,

Lars

Ian Collins 01-21-2008 07:52 AM

Re: Definition of logical true in C++?
 
Lars Uffmann wrote:
> Sebastian Redl wrote:
>> As defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.

>
> Thanks, that's all I needed to know - though I just noticed that there's
> no easily found online version of the C++ standards - are you able to
> point me to one?
>

http://webstore.ansi.org/RecordDetai...IEC+14882-2003

--
Ian Collins.

Lars Uffmann 01-21-2008 08:00 AM

Re: Definition of logical true in C++?
 
Ian Collins wrote:
> http://webstore.ansi.org/RecordDetai...IEC+14882-2003


Hmm - so the standard for THE programming language (imho) is not freely
available?

Not that I mind ordering a copy... just wondrin'... *headscratch*

Thank you :)

Lars

Sebastian Redl 01-21-2008 08:04 AM

Re: Definition of logical true in C++?
 
Lars Uffmann wrote:

> Ian Collins wrote:
>>

http://webstore.ansi.org/RecordDetai...IEC+14882-2003
>
> Hmm - so the standard for THE programming language (imho) is not freely
> available?


That's correct. ISO makes some money by selling the standard documents.

However, the drafts of the standard are freely available (search for C++
last public draft) and differ from the final version only in some rather
small issues. (The biggest difference I've found so far is in the rules
concerning reinterpret_cast.)

--
Sebastian Redl

Lars Uffmann 01-21-2008 08:11 AM

Re: Definition of logical true in C++?
 
Lars Uffmann wrote:
> Ian Collins wrote:
>> http://webstore.ansi.org/RecordDetai...IEC+14882-2003

> Not that I mind ordering a copy... just wondrin'... *headscratch*


Argl... That license agreement says "single computer only"... I guess
I'll go for a printed book version :) Amazon, here I come...

Regards,

Lars

Lars Uffmann 01-21-2008 08:22 AM

C++ Standard hardcopy (was: Re: Definition of logical true in C++?)
 
Sebastian Redl wrote:
> Lars Uffmann wrote:
>
>> Ian Collins wrote:

> http://webstore.ansi.org/RecordDetai...IEC+14882-2003
>> Hmm - so the standard for THE programming language (imho) is not freely
>> available?

>
> That's correct. ISO makes some money by selling the standard documents.


Okay, I guess I don't mind... Thanks for the hint with the drafts.
As for a hardcopy of the standard - all I seem to be able to find is
http://www.amazon.com/C%2B%2B-Standa...0903548&sr=1-1
- is there any other book that I've been overlooking?

Thanks!

Lars

Alf P. Steinbach 01-21-2008 08:33 AM

Re: Definition of logical true in C++?
 
* Lars Uffmann:
> Lars Uffmann wrote:
>> Ian Collins wrote:
>>> http://webstore.ansi.org/RecordDetai...IEC+14882-2003

>>
>> Not that I mind ordering a copy... just wondrin'... *headscratch*

>
> Argl... That license agreement says "single computer only"... I guess
> I'll go for a printed book version :) Amazon, here I come...


In order to use the standard, you really need a searchable document.

Without searchability, all you have is a pile of expensive paper,
because relevant paragraphs for some issue are generally scattered
throughout the standard -- because the standard has evolved from a
relatively small document, keeping the document structure while adding
in new stuff and amendning existing text here and there (it really needs
quite a bit of refactoring! :-) ).

I recommend downloading the latest draft from the committee pages (it's
in PDF format), and familiarizing yourself with use of that, before
paying hard cash for flaked dead trees.


Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Lars Uffmann 01-21-2008 08:58 AM

Re: Definition of logical true in C++?
 
Alf P. Steinbach wrote:
> In order to use the standard, you really need a searchable document.

Valid point, the thing is, I need the standard as a reference for my
department within the german space agency. A 1-workstation-license isn't
really doing us much good.

> I recommend downloading the latest draft from the committee pages (it's
> in PDF format), and familiarizing yourself with use of that, before
> paying hard cash for flaked dead trees.


I am still having a hard time finding a pdf of the latest draft - C++98
is what I need I guess - and the committee seems to be going out of its
way to hide any download links very well deep down in the site... I'll
keep searching..

Best Regards,

Lars


All times are GMT. The time now is 06:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57