Constructs



 DEVELOP > c-Plus-Plus > Constructs

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.




  Page 1 of 1

1

 


 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER