| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Landrew" |
| Date: |
11 Dec 2004 04:55:20 PM |
| Object: |
Constructs |
There is a new book-ish like entity that is freely available on the web:
"Constructs of the C++ Proramming Language"
The book is intended to serve as a light-weight reference for developers
with modest experience in C++.
Enjoy,
Landrew
.
|
|
| User: "Landrew" |
|
| Title: Re: Constructs |
11 Dec 2004 04:58:19 PM |
|
|
Doh!
To be found at www.landrew.com
"Landrew" <news04@landrew.com> wrote in message
news:tdCdnZBBmptw5ybcRVn-uw@speakeasy.net...
There is a new book-ish like entity that is freely available on the web:
"Constructs of the C++ Proramming Language"
The book is intended to serve as a light-weight reference for developers
with modest experience in C++.
Enjoy,
Landrew
.
|
|
|
|
| User: "Niels Dekker - no reply address" |
|
| Title: Re: Constructs |
12 Dec 2004 09:30:31 AM |
|
|
Landrew wrote:
"Constructs of the C++ Proramming Language"
To be found at www.landrew.com
Cool! Thanks!
www.landrew.com/cgi-bin/Via/Eval.pl?site=landrew&page=Article&article=01+Strings&path=/Languages/C%2B%2B/Constructs/Strings
says:
void process()
{
char s[100] = "hop on!";
}
The first seven positions in s are set to 'h', 'o', 'p', ' '
(space), 'o', 'n', '!'. The eigth position is set to a special
end of string marker, called the null character. The null
character is denoted by '\0' when it explicitly appears in code.
s[8] to s[99] are set to a null character as well.
Thus the code above has the same effect as the following:
void process()
{
char s[100];
s[0] = 'h';
s[1] = 'o';
s[2] = 'p';
s[3] = ' ';
s[4] = 'o';
s[5] = 'n';
s[6] = '!';
s[7] = '\0'; // end of string marker (null character)
}
This version will leave s[8] to s[99] uninitialized. Also it might take
less memory during runtime, because it won't store this literal string,
"hop on!".
Regards,
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
.
|
|
|
| User: "Landrew" |
|
| Title: Re: Constructs |
12 Dec 2004 10:32:13 AM |
|
|
s[8] to s[99] are set to a null character as well.
interesting. are you certain about that? i would have thought it would be
true for global variables, but not for local variables.
just as this initializes x to zero
----
int x;
int main()
{
...
}
----
but this does not
----
int main()
{
int x;
...
}
----
at least that is what i thought :)
landrew
"Niels Dekker - no reply address" <unknown@this.is.invalid> wrote in message
news:41BC6417.24B2D4E6@this.is.invalid...
Landrew wrote:
"Constructs of the C++ Proramming Language"
To be found at www.landrew.com
Cool! Thanks!
www.landrew.com/cgi-bin/Via/Eval.pl?site=landrew&page=Article&article=01+Strings&path=/Languages/C%2B%2B/Constructs/Strings
says:
void process()
{
char s[100] = "hop on!";
}
The first seven positions in s are set to 'h', 'o', 'p', ' '
(space), 'o', 'n', '!'. The eigth position is set to a special
end of string marker, called the null character. The null
character is denoted by '\0' when it explicitly appears in code.
s[8] to s[99] are set to a null character as well.
Thus the code above has the same effect as the following:
void process()
{
char s[100];
s[0] = 'h';
s[1] = 'o';
s[2] = 'p';
s[3] = ' ';
s[4] = 'o';
s[5] = 'n';
s[6] = '!';
s[7] = '\0'; // end of string marker (null character)
}
This version will leave s[8] to s[99] uninitialized. Also it might take
less memory during runtime, because it won't store this literal string,
"hop on!".
Regards,
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
.
|
|
|
| User: "Niels Dekker - no reply address" |
|
| Title: Re: Constructs |
12 Dec 2004 05:00:04 PM |
|
|
www.landrew.com says:
void process()
{
char s[100] = "hop on!";
}
The first seven positions in s are set to 'h', 'o', 'p', ' '
(space), 'o', 'n', '!'. The eigth position is set to a special
end of string marker, called the null character. The null
character is denoted by '\0' when it explicitly appears in code.
And I commented:
s[8] to s[99] are set to a null character as well.
Landrew wrote:
interesting. are you certain about that?
Well... home.tiscalinet.ch/t_wolf/tw/c/string_init.html says:
yes, if a string literal in an initializer contains less characters
than the array has elements, the remaining elements are set to 0.
I guess the same holds in C++.
Regards,
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
.
|
|
|
|
|
|
|