|
From: Ioannis V. <no...@ho...> - 2003-02-27 11:00:22
|
-------Original Message-------=0D
=0D
From: gi...@li...=0D
Date: =D0=DD=EC=F0=F4=E7, 27 =D6=E5=E2=F1=EF=F5=DC=F1=E9=EF=F2 2003 7:13:=
25 =F0=EC=0D
To: Dev-C++ Mailing List=0D
Subject: Re: [Dev-C++] need some explanation=0D
=0D
On Tue, Feb 25, 2003 at 05:10:26PM +0200, Ioannis Vranos wrote:=0D
> Actually that information is wrong. stdlib.h and cstdlib are part of th=
e
C++=0D
> standard (the C subset of C++ but it doesn't matter). And do not confus=
e
C++=0D
> with C, they are different languages. Example:=0D
> =0D
> C99 code but not valid C++:=0D
> =0D
> #include <stddef.h>=0D
> #include <stdio.h>=0D
> =0D
> =0D
> int main()=0D
> {=0D
> size_t s=3D7;=0D
> =0D
> printf("%sz\n", s);=0D
> =0D
> }=0D
> =0D
> =0D
> Even between C90 vs C++98 there are differences. For example:=0D
> =0D
> int main()=0D
> {=0D
> char s[10]=3D"0123456789";=0D
> =0D
> return 0; =0D
> }=0D
> =0D
> is valid C90 but not C++.=0D
> =0D
> =0D
=0D
Hello Ioannis,=0D
=0D
I do not know C99, but I seem to get that the "strange" part=0D
of the C99 code you wrote is the format used: "s" is a (sort of) =0D
integer and one can't print it as a string. =0D
=0D
=0D
=3D=3D> In C99, size_t is still a typedef, but it can be a typedef of som=
e=20
exotic" type, that is not of those standard built in types that are provi=
ded
In C99 the built in types long long and _Bool (yes _Bool), as integral
types have been added and size_t can be larger than long long, and a spec=
ial
format specifier has been added, %sz. =0D
=0D
=3D=3D> In the contrary, in both C90 and C++98, size_t is a typedef of on=
e of
the provided built in types (usually unsigned long). So in C90 if you wan=
ted
to printf() a size_t you would do:=0D
=0D
size_t something=3D0;=0D
=0D
=2E..=0D
=0D
printf(%lu\n", (unsigned long)something));=0D
=0D
=3D=3D> I would agree with the %sz specifier so as to not need casting an=
d work
with whatever typedef size_t is, but all the rest are really crap (as you
can understand i strongly do not like C99).=0D
=0D
=0D
=0D
I'm more concerned about the second piece of code, as I happen to =0D
use C89 and C++98). It looks OK to me for both the languages, could =0D
you shed some light on why it is not C++98?=0D
=0D
=0D
=3D=3D> Because the initialization string contains an additional characte=
r, '\0'
and C++98 protects you in case you made a mistake.=0D
=0D
=0D
=0D
Ioannis Vranos=0D
=0D
* Programming pages: http://www.noicys.freeurl.com=0D
* Alternative URL: http://run.to/noicys=20 |