Need Clarification

N

Newbie

Can u tell me more abt how did the array a[20] got converted into string
a...!!

To this question some-one answered :

No, it won't convert into string object.
Here the representation of string is as character arrays.

Ok.This part is fine.

It can be classifieds depends on the character used to indicate the end
of the string. "In C it is ASCII-Z representation and end with ASCII
value 0"

Is this comment correct ? I did not find anything similar in the C
standard or am i missing something ?

What about systems that don't use the ASCII character set (say if they
use EBCDIC instead ?)
 
W

Walter Roberson

Can u tell me more abt how did the array a[20] got converted into string
a...!!
To this question some-one answered :
No, it won't convert into string object.
Here the representation of string is as character arrays.
Ok.This part is fine.
It can be classifieds depends on the character used to indicate the end
of the string. "In C it is ASCII-Z representation and end with ASCII
value 0"
Is this comment correct ? I did not find anything similar in the C
standard or am i missing something ?
What about systems that don't use the ASCII character set (say if they
use EBCDIC instead ?)

No matter which character set you are using, C strings are stored in
C array of char, and the string may be smaller than the array that it
is stored in. The end of the string (as opposed to the end of the
char array) is the first array entry with numeric value 0; if that
numeric 0 happens to be right at the beginning of the array, then the
string is commonly referred to as being "empty" -- but note that
an "empty" string actually needs to have one value stored in it, the
numeric 0 that marks the end of the string.
 
B

Ben Bacarisse

Newbie said:
Can u tell me more abt how did the array a[20] got converted into
string a...!!

To this question some-one answered :

No, it won't convert into string object.
Here the representation of string is as character arrays.

Ok.This part is fine.

It can be classifieds depends on the character used to indicate the
end of the string. "In C it is ASCII-Z representation and end with
ASCII value 0"

Is this comment correct ? I did not find anything similar in the C
standard or am i missing something ?

What about systems that don't use the ASCII character set (say if they
use EBCDIC instead ?)

This seems to be the middle of a conversation but I have no context
for it so all I can say is:

A character array can be said to hold a C string if it has a zero byte
somewhere in it. All C strings are zero terminated. A character
array without a zero byte is just an array of characters. The
character set is not important -- only that the byte that marks the
end be arithmetically zero. All sane character sets ensure that zero
can be used for this purpose.

In fact, an array can hold more than one string, but exactly how many
is a matter of definition. This array:

char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };

has at least two strings in it: the C expressions my_strings and
my_strings + 4 both point to the start of valid strings (some people
choose to say that my_strings *is* a string -- feel free to do that in
casual conversation, but technically it is a pointer to the start of a
string).

my_strings + 1, my_strings + 2, and so on also point to (the start of)
strings, so that array can be said to hold 5 strings that would
compare as being different. It has two zero length strings
(my_strings + 3 and my_strings + 5) but they compare equal.

Hope that helps.
 
N

Newbie

Ben said:
Newbie said:
Can u tell me more abt how did the array a[20] got converted into
string a...!!

To this question some-one answered :

No, it won't convert into string object.
Here the representation of string is as character arrays.

Ok.This part is fine.

It can be classifieds depends on the character used to indicate the
end of the string. "In C it is ASCII-Z representation and end with
ASCII value 0"

Is this comment correct ? I did not find anything similar in the C
standard or am i missing something ?

What about systems that don't use the ASCII character set (say if they
use EBCDIC instead ?)

This seems to be the middle of a conversation but I have no context
for it so all I can say is:

A character array can be said to hold a C string if it has a zero byte
somewhere in it. All C strings are zero terminated. A character
array without a zero byte is just an array of characters. The
character set is not important -- only that the byte that marks the
end be arithmetically zero. All sane character sets ensure that zero
can be used for this purpose.

In fact, an array can hold more than one string, but exactly how many
is a matter of definition. This array:

char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };

has at least two strings in it: the C expressions my_strings and
my_strings + 4 both point to the start of valid strings (some people
choose to say that my_strings *is* a string -- feel free to do that in
casual conversation, but technically it is a pointer to the start of a
string).

my_strings + 1, my_strings + 2, and so on also point to (the start of)
strings, so that array can be said to hold 5 strings that would
compare as being different. It has two zero length strings
(my_strings + 3 and my_strings + 5) but they compare equal.

Hope that helps.
Thanks You all.The only thing i wanted to know was whether it was right
to say "In C it is ASCII-Z representation and end with ASCII value 0"

My point was the All C guaranteed was that every string is NULL
terminated.It does not require the implementation to use ASCII character
set.

Thanks again for the quick replies.
 
B

Ben Bacarisse

Newbie said:
Thanks You all.The only thing i wanted to know was whether it was
right to say "In C it is ASCII-Z representation and end with ASCII
value 0"

It may be daft to labour the point (you seem happy with the answers)
but the reason I did not answer this question is that I can't put any
meaning to the words. I can't link the two clauses with "and" and the
only meaning I can give to "ASCII-Z representation" (the number 90)
makes not sense in this context.

One often reads things like "ASCII value 0". But the word "ASCII" has
no meaning here. ASCII value 0 is the value 0. It is a property of
all encodings that "Froodle value 90" is 90. What 90 *means* in the
Froodle character set is, of course, a matter for the Froodle
standards committee. If they decide that the character 'A' is to be
represented by the value 0, then it is not possible to use Froodle as
the execution character set for a C implementation because it is the
value 0 (regardless of any meaning it might have) that terminates
strings in C, and C insists that strings be both zero terminated and
be able to hold the character 'A'.

Anyway, I am glad that you are content. If this is more than you
want to know, I apologise.
My point was the All C guaranteed was that every string is NULL
terminated.

Be careful with your terms. Strings are null terminated, not NULL
terminated. NULL is a macro which expands to a pointer --
specifically a null pointer constant. Think of NULL as a noun (it is
the name of a macro after all). The word "null" is an adjective --
you can have a null pointer and a null character is used to terminate
strings.
 
N

Newbie

Ben said:
It may be daft to labour the point (you seem happy with the answers)
but the reason I did not answer this question is that I can't put any
meaning to the words. I can't link the two clauses with "and" and the
only meaning I can give to "ASCII-Z representation" (the number 90)
makes not sense in this context.

One often reads things like "ASCII value 0". But the word "ASCII" has
no meaning here. ASCII value 0 is the value 0. It is a property of
all encodings that "Froodle value 90" is 90. What 90 *means* in the
Froodle character set is, of course, a matter for the Froodle
standards committee. If they decide that the character 'A' is to be
represented by the value 0, then it is not possible to use Froodle as
the execution character set for a C implementation because it is the
value 0 (regardless of any meaning it might have) that terminates
strings in C, and C insists that strings be both zero terminated and
be able to hold the character 'A'.

Anyway, I am glad that you are content. If this is more than you
want to know, I apologise.

This was enlightening! Thank You.
 
W

Walter Roberson

Ben Bacarisse said:
only meaning I can give to "ASCII-Z representation" (the number 90)
makes not sense in this context.

ASCII-Z is a term that means zero-terminated list of ASCII characters
of indefinite size.

It goes along with ASCII-C (I think it is) that means a list of ASCII
characters prefixed with a size count; I'm not positive as to how big
the count is, but 2 bytes is the figure that comes to mind.
 
K

Keith Thompson

Ben Bacarisse said:
In fact, an array can hold more than one string, but exactly how many
is a matter of definition. This array:

char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };

has at least two strings in it: the C expressions my_strings and
my_strings + 4 both point to the start of valid strings

Yes, since 6 is at least two. (I see that you addressed this below.)
(some people
choose to say that my_strings *is* a string -- feel free to do that in
casual conversation, but technically it is a pointer to the start of a
string).

Yes and no. ``my_strings'' is the name of an object. That object is
an array object, not a pointer object. On the other hand, if the name
``my_object'' is used as an expression, it will usually be implicitly
converted to a pointer value (a char* pointing to the 'a'). On the
other other hand, this conversion doesn't happen if ``my_object'' is
the operand of a unary "&" or "sizeof" operator.

So whether "my_object is a pointer" depends on whether you mean the
object named "my_object" or the expression my_object.
 
B

Ben Bacarisse

ASCII-Z is a term that means zero-terminated list of ASCII characters
of indefinite size.

Ah. Not an abbreviation I've come across. That makes it clear that
the OP was only concerned to know that ASCII is not mandated by C.
 
B

Ben Bacarisse

Keith Thompson said:
Ben Bacarisse said:
In fact, an array can hold more than one string, but exactly how many
is a matter of definition. This array:

char my_strings[] = { 'a', 'b', 'c', '\0', 'd', '\0' };

has at least two strings in it: the C expressions my_strings and
my_strings + 4 both point to the start of valid strings

Yes, since 6 is at least two. (I see that you addressed this
below.)

I knew I'd have to!
Yes and no. ``my_strings'' is the name of an object. That object is
an array object, not a pointer object. On the other hand, if the name
``my_object'' is used as an expression, it will usually be implicitly
converted to a pointer value (a char* pointing to the 'a'). On the
other other hand, this conversion doesn't happen if ``my_object'' is
the operand of a unary "&" or "sizeof" operator.

So whether "my_object is a pointer" depends on whether you mean the
object named "my_object" or the expression my_object.

Yes. I did say "the expressions my_strings and my_strings + 4" but
obviously I should have repeated "the expression" in the parenthetical
remark to avoid ambiguity. I'll get the hang of c.l.c eventually.
 
K

Keith Thompson

Ben Bacarisse said:
Ah. Not an abbreviation I've come across. That makes it clear that
the OP was only concerned to know that ASCII is not mandated by C.

The term I've seen is "asciz". It is, for example, an assembler
directive; something like
.asciz "hello"
creates a constant containing "hello" followed by '\0', whereas
.ascii "hello"
might create a similar constant without the '\0'. (Not directly
relevant to C, but relevant to understanding what's being discussed.)
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top