473,320 Members | 1,859 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,320 software developers and data experts.

Is "hello, world" a constant

Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the
"hello, world" thing using the name "string-constant". But `ISO/IEC
9899:TC2' does not include this kind of thing in section `A.1.5
Constants'.

May 19 '06 #1
3 2322
ed
On 19 May 2006 12:02:45 -0700
"lovecreatesbeauty" <lo***************@gmail.com> wrote:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the
"hello, world" thing using the name "string-constant". But `ISO/IEC
9899:TC2' does not include this kind of thing in section `A.1.5
Constants'.


It might have helped if you quoted those sections. "Hello world" is a
literal. It is immutable. You cannot change this what-so-ever, unless
it is given as via a copy function:

char s[20] = "Hello world";

This allocated memory for s, straight after the characters are copied
in.

--
Regards, Ed :: http://www.usenix.org.uk
just another perl person
:%s/Open Source/Free Software/g :: Free DNS available

May 19 '06 #2
"lovecreatesbeauty" <lo***************@gmail.com> writes:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the
"hello, world" thing using the name "string-constant". But `ISO/IEC
9899:TC2' does not include this kind of thing in section `A.1.5
Constants'.


You'll find it in the following section, "String literals".

In the C99 grammar, we have:

token:
keyword
identifier
constant
string-literal
punctuator

constant:
integer-constant
floating-constant
enumeration-constant
character-constant

primary-expression:
identifier
constant
string-literal
( expression )

"primary-expression" and "token" are the only productions that refers
to "constant".

Making a "string-literal" a separate kind of token, rather than
another kind of "constant", was an arbitrary choice. The following
would describe exactly the same language:

token:
keyword
identifier
constant
/* remove string-literal */
punctuator

constant:
integer-constant
floating-constant
enumeration-constant
character-constant
string-literal /* add this */

primary-expression:
identifier
constant
/* remove string-literal */
( expression )

The wording in K&R2 and H&S5 is just a slightly different way of
describing exactly the same thing.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 19 '06 #3
On Fri, 19 May 2006 19:31:45 GMT, ed <ed@noreply.com> wrote in
comp.lang.c:
On 19 May 2006 12:02:45 -0700
"lovecreatesbeauty" <lo***************@gmail.com> wrote:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the
"hello, world" thing using the name "string-constant". But `ISO/IEC
9899:TC2' does not include this kind of thing in section `A.1.5
Constants'.
It might have helped if you quoted those sections. "Hello world" is a
literal. It is immutable. You cannot change this what-so-ever, unless


Specifically, a string literal.

It may or may not be immutable. It has the type "array of char" in C,
and specifically does not have the type "array of const char".
Attempting to modify a string literal produces undefined behavior not
because it has the type "array of const char", but merely because the
C standard specifically states that it does.
it is given as via a copy function:
I have no idea what the above phrase means. There is no function
involved in your code snippet below.
char s[20] = "Hello world";
This is a declaration of an object with initialization, there is no
function involved here.
This allocated memory for s, straight after the characters are copied
in.


This causes the array 's' to be initialized at its creation with the
11 characters inside the quoted string literal followed by 9 '\0'
characters. How this initialization is performed is up to the
implementation. There need not be a "copy function" involved.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
May 21 '06 #4

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

Similar topics

2
by: ME | last post by:
I am trying to find a prewritten method for converting a string like this:"Hello World" to this "Hello\sWorld". I plan to use it to build a regular expression. Specifically I am looking for a...
9
by: PG | last post by:
Hi gurus, I have AIX visual age C++ compiler version 5.0.2.3. I have a simple hello world program that gives compilation errors. Any help will be appreciated. Thanks PG ***test.cpp**** ...
6
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
23
by: Hans | last post by:
Hello, Why all C/C++ guys write: const char* str = "Hello"; or const char str = "Hello";
33
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use...
42
by: Prashanth Badabagni | last post by:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
4
by: arnuld | last post by:
i am learning C and doing the exercise 1-1 of K&R2, where K&R ask to remove some parts of programme and experiment with error, so here i go: #include <stdio.h> int main () { printf('hello...
0
by: Gerardo Herzig | last post by:
Hi all. Im having some "problems" with a small concurrent plpython function. Based on a small example about concurrent programming, there is some code which works fine under python: #!...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.