What does it mean

J

jacob navia

rsk said:
char *i_reg_fname = "none";
the variable "i_reg_fname" is a pointer to characters. It is
initialized to point to the character array "none".
 
K

karthikbalaguru

please include the subject line information in the body of your post

Subject: "What does it mean"



don't include sigs (the bit after "-- "


i_reg_fname is not a string constant

String constants are sequences of characters enclosed in double
quotes.
String literal is the formal term for a double-quoted string in C
source.
'i_reg_fname' is a pointer to characters.

Here,
Note that any attempt to modify the string that 'i_reg_fname' points
to will
result in undefined behaviour.
that is, i_reg_fname[0]='q'; // not allowed . will cause undefined
behaviour. :(

Some compilers have a switch controlling whether string literals are
writable or not (for compiling old code),
and some may have options to cause string literals to be formally
treated as arrays of const char (for better error catching).

But irrespective of theat, if you have declared as below , then it is
possible to change.
char i_reg_fname[] = "none";
that is, i_reg_fname[0]='q'; // allowed . :)

Karthik Balaguru
 
K

karthikbalaguru

please include the subject line information in the body of your post
Subject: "What does it mean"
don't include sigs (the bit after "-- "
i_reg_fname is not a string constant

String constants are sequences of characters enclosed in double
quotes.
String literal is the formal term for a double-quoted string in C
source.
'i_reg_fname' is a pointer to characters.

Here,
Note that any attempt to modify the string that 'i_reg_fname' points
to will
result in undefined behaviour.
that is, i_reg_fname[0]='q'; // not allowed . will cause undefined
behaviour. :(

Some compilers have a switch controlling whether string literals are
writable or not (for compiling old code),
and some may have options to cause string literals to be formally
treated as arrays of const char (for better error catching).

But irrespective of theat, if you have declared as below , then it is
possible to change.
char i_reg_fname[] = "none";
that is, i_reg_fname[0]='q'; // allowed . :)

i_reg_fname is a non-const pointer to char.
It may point to a string literal, but it isn't declared const.

An attempt to modify it will cause undefined behaviour .
Attempting to modify a string literal invokes undefined
behavior, because the C standard defines that attempting to modify a
string literal invokes undefined behavior.
It is because of the C standard and it is not 'const'.

In actual practice, the behaviour depends on where the compiler
decides to put
its string constants. Some compilers have a switch controlling whether
string literals are
writable or not (for compiling old code),and some may have options to
cause string
literals to be formally treated as arrays of const char (for better
error catching).

Earlier C didn not have the 'const' keyword, so if you wanted to pass
a string
literal to a particular function( In sucha a way that the string will
not be modified inside the
function), then that particular function must take a 'char*' argument.
Thats all.

Lot of information is available regarding this String Literal in
internet and groups.

Karthik Balaguru
 
B

Barry Schwarz

please include the subject line information in the body of your post
Subject: "What does it mean"
On 27 Sep, 14:05, karthikbalaguru <[email protected]> wrote:
char *i_reg_fname = "none";
don't include sigs (the bit after "-- "
String Constant.
i_reg_fname is not a string constant

String constants are sequences of characters enclosed in double
quotes.
String literal is the formal term for a double-quoted string in C
source.
'i_reg_fname' is a pointer to characters.

Here,
Note that any attempt to modify the string that 'i_reg_fname' points
to will
result in undefined behaviour.
that is, i_reg_fname[0]='q'; // not allowed . will cause undefined
behaviour. :(

Some compilers have a switch controlling whether string literals are
writable or not (for compiling old code),
and some may have options to cause string literals to be formally
treated as arrays of const char (for better error catching).

But irrespective of theat, if you have declared as below , then it is
possible to change.
char i_reg_fname[] = "none";
that is, i_reg_fname[0]='q'; // allowed . :)

i_reg_fname is a non-const pointer to char.
It may point to a string literal, but it isn't declared const.

An attempt to modify it will cause undefined behaviour .
Attempting to modify a string literal invokes undefined
behavior, because the C standard defines that attempting to modify a
string literal invokes undefined behavior.
It is because of the C standard and it is not 'const'.

In actual practice, the behaviour depends on where the compiler
decides to put

In actual practice, the behavior is undefined. The fact that
undefined behavior sometimes APPEARS to do what you want does not make
it any less undefined.
its string constants. Some compilers have a switch controlling whether
string literals are
writable or not (for compiling old code),and some may have options to
cause string
literals to be formally treated as arrays of const char (for better
error catching).

Earlier C didn not have the 'const' keyword, so if you wanted to pass
a string
literal to a particular function( In sucha a way that the string will
not be modified inside the
function), then that particular function must take a 'char*' argument.
Thats all.

Lot of information is available regarding this String Literal in
internet and groups.


Remove del for email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top