473,226 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

The C Standard Library


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
6 1792
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: skoco | last post by:
Hello! Do you know when will be the new standard for c++ approved? And WHAT will be inside? Hope there will be some thread and synchro classes, text and XML parsing, new containers and other new...
71
by: Christopher Benson-Manica | last post by:
At what point was the .h dropped from the STL headers? I just had a discussion yesterday with my boss, who said he wanted .h on all the STL includes, despite me protesting that it was not...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
8
by: Sensei | last post by:
I have a quick question about the math library included in the standard C90 (and 99). The gcc, xlc and possibly other compilers/linkers on some unix platforms cannot use any math functions in...
6
by: junky_fellow | last post by:
On what basis it is decided that a particular funtion should be a part of Standard C library ? Do I get these standard C libraries along with the C compiler ? Or I can use the c complier from...
3
by: arnuld | last post by:
Hello, i posted this question more than 1 month ago but did not get any answers, so i am posting it again (1). with advice form archives @ alt.comp.lang.learn.c-c++, comp.lang.c++,...
22
by: David Mathog | last post by:
One thing that keeps coming up in this forum is that standard C lacks many functions which are required in a workstation or server but not possible in an embedded controller. This results in a...
20
by: J de Boyne Pollard | last post by:
MThe library functions which are included to allow process Mlaunch, forking, and termination, imply that it is both Mpossible and desirable for a process to fork itself. This is Ma fundamental...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
16
by: subramanian100in | last post by:
Program 1: --------------- #include <cstdlib> #include <iostream> #include <vector> using namespace std; int main() {
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.