|
From: Samuel K. <ib...@ly...> - 2003-02-27 06:30:42
|
It is because the char array is to long for C++ (I don't know C90 so I'll just tell you what I know about the C++). C++ ends a string with array with the '\0' character. It is its way of terminating a string. When an array is created, if '\0' is not already at the end of the char string, the compiler will automatically append '\0' to the end of the array. The trouble in the example though is that you have 10 chars, and the compiler is trying to add another char. This is going to cause your array to overflow and generate a compiler error. (Note: Compiler errors will only be made when you are initializing your string in this manner. If you had
char s[] = "0123456789";
it would compile perfectly okay, except your array would be 11 chars long.)
--
On Wed, 26 Feb 2003 18:14:34
Luigi Santillo wrote:
>On Tue, Feb 25, 2003 at 05:10:26PM +0200, Ioannis Vranos wrote:
>> Actually that information is wrong. stdlib.h and cstdlib are part of the C++
>> standard (the C subset of C++ but it doesn't matter). And do not confuse C++
>> with C, they are different languages. Example:
>>
>> C99 code but not valid C++:
>>
>> #include <stddef.h>
>> #include <stdio.h>
>>
>>
>> int main()
>> {
>> size_t s=7;
>>
>> printf("%sz\n", s);
>>
>> }
>>
>>
>> Even between C90 vs C++98 there are differences. For example:
>>
>> int main()
>> {
>> char s[10]="0123456789";
>>
>> return 0;
>> }
>>
>> is valid C90 but not C++.
>>
>>
>
>Hello Ioannis,
>
>I do not know C99, but I seem to get that the "strange" part
>of the C99 code you wrote is the format used: "s" is a (sort of)
>integer and one can't print it as a string.
>
>I'm more concerned about the second piece of code, as I happen to
>use C89 and C++98). It looks OK to me for both the languages, could
>you shed some light on why it is not C++98?
>
>TIA
>--
>>> gisan >>
>If you stand on your head, you will get footprints in your hair.
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Scholarships for Techies!
>Can't afford IT training? All 2003 ictp students receive scholarships.
>Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
>www.ictp.com/training/sourceforge.asp
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
_____________________________________________________________
Get 25MB, POP3, Spam Filtering with LYCOS MAIL PLUS for $19.95/year.
http://login.mail.lycos.com/brandPage.shtml?pageId=plus&ref=lmtplus
|