By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

The C Standard Library

P: n/a

I gather that, rather than the C++ Standard defining the functionality of
the Standard Library features which it has in common with C, it makes
reference to a C Standard which defines their functionality.

Is the C Standard in question C89 (or C90 as some call it)?

Does the C++ Standard make any changes to the C Standard Library which it
inherits? For example, in C, the "toupper" function takes an argument of
int, and the value passed to it must be within range of an unsigned char.
Are things the same in C++? If so, the following program can invoke
undefined behaviour:

#include <cctype>

int main()
{
toupper('a');
}
Why? Because 'a' might be a negative number.

A better example would be the use of extended characters, which are far
more likely to be a negative number:

toupper( 'German sharp s' );
To remedy this, many C programmers always cast the argument:

toupper( (unsigned char)'German sharp s' );
--

Frederick Gotham
Jul 5 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Frederick Gotham wrote:
I gather that, rather than the C++ Standard defining the functionality of
the Standard Library features which it has in common with C, it makes
reference to a C Standard which defines their functionality.

Is the C Standard in question C89 (or C90 as some call it)?
Yes, with the 1995 amendment AM1.
Does the C++ Standard make any changes to the C Standard Library which it
inherits?
Yes, Annex C of the C++ standard describes the various changes, such as
the fact that wchar_t is no longer a typedef (which was a mistake, IMHO.
It would have been more consistent to call the new type wchar, and to
have kept wchar_t as a typedef (which is what _t usually designates)).
Other major changes are:
typedefs and macros from C that are now C++ keywords are removed from
the headers
<cstringincludes some const overloads
atexit, exit, abort and longjmp have different semantics
offsetof only works for a subset of types - POD types
malloc and friends are forbidden from calling ::operator new.

For example, in C, the "toupper" function takes an argument of
int, and the value passed to it must be within range of an unsigned char.
Are things the same in C++?
Yes, the vast majority is unchanged.

Tom
Jul 5 '06 #2

P: n/a
Frederick Gotham wrote:
I gather that, rather than the C++ Standard defining the
functionality of the Standard Library features which it has in common
with C, it makes reference to a C Standard which defines their
functionality.

Is the C Standard in question C89 (or C90 as some call it)?
Yes.
Does the C++ Standard make any changes to the C Standard Library
which it inherits?
Yes, some. But they don't concern interfaces. Mostly macros and
namespace 'std'.
For example, in C, the "toupper" function takes an
argument of int, and the value passed to it must be within range of
an unsigned char. Are things the same in C++?
Yes. No change is mentioned in the C++ Standard.
If so, the following
program can invoke undefined behaviour:

#include <cctype>

int main()
{
toupper('a');
}
Why? Because 'a' might be a negative number.
Really? Any real-world example of a character set where 'a' is in fact
a negative number?
A better example would be the use of extended characters, which are
far more likely to be a negative number:

toupper( 'German sharp s' );
To remedy this, many C programmers always cast the argument:

toupper( (unsigned char)'German sharp s' );
But the Standard explicitly prohibits 'German sharp s' to be in the
source character set. Read 2.2.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 5 '06 #3

P: n/a
In article <jn*******************@news.indigo.ie>,
Frederick Gotham <fg*******@SPAM.comwrote:
I gather that, rather than the C++ Standard defining the functionality of
the Standard Library features which it has in common with C, it makes
reference to a C Standard which defines their functionality.

Is the C Standard in question C89 (or C90 as some call it)?

Does the C++ Standard make any changes to the C Standard Library which it
inherits? For example, in C, the "toupper" function takes an argument of
int, and the value passed to it must be within range of an unsigned char.
Are things the same in C++? If so, the following program can invoke
undefined behaviour:

#include <cctype>

int main()
{
toupper('a');
}
Why? Because 'a' might be a negative number.
As I understand it, 'toupper' only looks at the first 7 bits or EOF. So
no undefined behavior there.
A better example would be the use of extended characters, which are far
more likely to be a negative number:

toupper( 'German sharp s' );
To remedy this, many C programmers always cast the argument:

toupper( (unsigned char)'German sharp s' );
Nether of the above are defined to work. 'German sharp s' is not a value
in the ASCII standard.
Jul 5 '06 #4

P: n/a
Daniel T. wrote:
In article <jn*******************@news.indigo.ie>,
Frederick Gotham <fg*******@SPAM.comwrote:
>I gather that, rather than the C++ Standard defining the
functionality of the Standard Library features which it has in
common with C, it makes reference to a C Standard which defines
their functionality.

Is the C Standard in question C89 (or C90 as some call it)?

Does the C++ Standard make any changes to the C Standard Library
which it inherits? For example, in C, the "toupper" function takes
an argument of int, and the value passed to it must be within range
of an unsigned char. Are things the same in C++? If so, the
following program can invoke undefined behaviour:

#include <cctype>

int main()
{
toupper('a');
}
Why? Because 'a' might be a negative number.

As I understand it, 'toupper' only looks at the first 7 bits or EOF.
So no undefined behavior there.
Where did you get the "first 7 bits"?
>A better example would be the use of extended characters, which are
far more likely to be a negative number:

toupper( 'German sharp s' );
To remedy this, many C programmers always cast the argument:

toupper( (unsigned char)'German sharp s' );

Nether of the above are defined to work. 'German sharp s' is not a
value in the ASCII standard.
Who said anything about ASCII? ASCII is just one supported encoding.
There are several others that are commonly used, and C++ has to work
fine with them. That is not to say that 'German sharp s' is going to
be accepted, though.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 5 '06 #5

P: n/a
On Wed, 05 Jul 2006 14:53:03 GMT, Frederick Gotham
<fg*******@SPAM.comwrote in comp.lang.c++:
>
I gather that, rather than the C++ Standard defining the functionality of
the Standard Library features which it has in common with C, it makes
reference to a C Standard which defines their functionality.

Is the C Standard in question C89 (or C90 as some call it)?

Does the C++ Standard make any changes to the C Standard Library which it
inherits? For example, in C, the "toupper" function takes an argument of
int, and the value passed to it must be within range of an unsigned char.
Are things the same in C++? If so, the following program can invoke
undefined behaviour:

#include <cctype>

int main()
{
toupper('a');
}
Why? Because 'a' might be a negative number.
No, it can't. Try reading the standard. Particularly paragraph 3 of
2.2 Character sets in this particular case.
A better example would be the use of extended characters, which are far
more likely to be a negative number:

toupper( 'German sharp s' );
To remedy this, many C programmers always cast the argument:

toupper( (unsigned char)'German sharp s' );
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 5 '06 #6

P: n/a
In article <jn*******************@news.indigo.ie>, fg*******@SPAM.com
says...

[ ... ]
Why? Because 'a' might be a negative number.
$2.2/3: "For each basic execution character set, the values of the
members shall be non-negative and distinct from
one another."
A better example would be the use of extended characters, which are far
more likely to be a negative number:
Read "far more likely" as "possible"...
toupper( 'German sharp s' );
To remedy this, many C programmers always cast the argument:

toupper( (unsigned char)'German sharp s' );
That's still necessary if the character isn't certain to fall within
a basic execution character set. If memory serves, locale
<char>::toupper takes a char as its parameter though.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 6 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.