473,406 Members | 2,619 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,406 software developers and data experts.

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
Jul 22 '05 #1
4 1305
Doh!

To be found at www.landrew.com
"Landrew" <ne****@landrew.com> wrote in message
news:td********************@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

Jul 22 '05 #2
Landrew wrote:

"Constructs of the C++ Proramming Language"

To be found at www.landrew.com
Cool! Thanks!
http://www.landrew.com/cgi-bin/Via/E...tructs/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
Jul 22 '05 #3
> 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" <un*****@this.is.invalid> wrote in message
news:41***************@this.is.invalid...
Landrew wrote:

"Constructs of the C++ Proramming Language"

To be found at www.landrew.com


Cool! Thanks!
http://www.landrew.com/cgi-bin/Via/E...tructs/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

Jul 22 '05 #4
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
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
1
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
5
by: masood.iqbal | last post by:
My simplistic mind tells me that having local variables within looping constructs is a bad idea. The reason is that these variables are created during the beginning of an iteration and deleted at...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
5
by: Marcos MOS | last post by:
Hi, I've put a appSetting tag into my web.config, but when I try to catch its value to my Image WebControl occurs the follow error: "Server tags cannot contain <% ... %> constructs." on...
1
by: Martin Schmid | last post by:
I'm getting a parser error message: Server tags cannot contain <% ... %> constructs... Ok.. so How do I accomplish this: For Each file in Files if ucase(right(file.name,7))<>ucase("_tn.jpg")...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
1
by: Neil Zanella | last post by:
Hello, I would like to do the following: <form method="post" action="<%= Request.ServerVariables %>" runat="server"> The reason I would like to do this is twofold:
2
by: portroe | last post by:
What would be a typical scenario or real-world reason to us Overload constructs, thanks portroe
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.