Re: HELP PLEASE - How to convert string to byte array
Lawrence Kirby <lknews@netacti ve.co.uk> writes:
[color=blue]
> On Sat, 11 Jun 2005 23:44:45 +0000, pete wrote:
>[color=green]
> > Lawrence Kirby wrote:
> >[color=darkred]
> >> Note that in the description above there is no
> >> such thing in C as a "byte
> >> object" (objects always have a type),
> >> a char object is a byte *sized* object.[/color]
> >
> > An allocated object doesn't always have a type.[/color]
>
> An allocated object is a grey area. The definition of the term "object"
> says it is a region of data storage then contents of which can represent
> values. Well a value in an object is an interpretation of a bit pattern
> according to the rules of a type - if you have no type you can't represent
> values.[/color]
Any object that is designated has a type, which is the type of the
expression used to designate it; section 6.3.2.1 p1.
Any object that is accessed has an effective type, which if it isn't
anything else is the type of the lvalue used to access it; section
6.5 p6.
Some objects have an "inherent type" in the sense that the memory
corresponds to (an instance of) a declared variable, and the variable
has a type. This "inherent type" shows up tacitly in the language of
6.5 p6, eg, "the declared type of the object, if any" (despite
effective type being defined only when accessing objects, and despite
the small inconsistency that variables, not objects, have a type
declared for them). Section 6.5 p6 specifically anticipates the
circumstance that an object not have an "inherent type", eg, "If a
value is stored into an object having no declared type ...".
Section 6.5 p7 imposes requirements on the relationship between the
type of an object (that was designated) and the effective type of an
object (that was accessed). Apparently there are no requirements
imposed on the relationship between type and effective type (or
"inherent type" for that matter), except in the case of access.
The language in the standard is confused about what the word "object"
means. It's defined (3.14) as 'a region of data storage in the
execution environment', but in lots of places in the text of the
standard it's used to mean something more like "an instance of a
variable". There is the example language above, talking about the
'declared type of the object', despite there being no definition of
what the "declared type" of an object is (at least not that I could
find). Also, although I don't have a reference, I'm pretty sure
I remember seeing a phrase like "an instance of the object", which
I took to mean that it's being used basically as a synonym for
variable.
To respond to the comment above - whenever an object is designated it
has a type, which is the type of the expression used to designate the
object; it is this type that is used to interpret what value might
be represented.
A region of storage need not have any type. Whenver that region of
storage takes part in a computation, a type is imposed on it by the
expression used to access it.
HELP PLEASE - How to convert string to byte array
Collapse
This topic is closed.
X
X
-
Guest replied -
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Lawrence Kirby wrote:[color=blue]
>
> On Sat, 11 Jun 2005 23:44:45 +0000, pete wrote:
>[color=green]
> > Lawrence Kirby wrote:
> >[color=darkred]
> >> Note that in the description above there is no
> >> such thing in C as a "byte
> >> object" (objects always have a type),
> >> a char object is a byte *sized* object.[/color]
> >
> > An allocated object doesn't always have a type.[/color]
>
> An allocated object is a grey area.[/color]
Not really.
In C99 there's 3 kinds of durations for objects,
and allocated is one of them.
[color=blue]
> The definition of the term "object"
> says it is a region of data storage then contents of which
> can represent values.[/color]
It can represent values,
as long as you do what takes to get the values in there.
An uninitialised object of type int,
can't represent values either,
but it's still an object.
[color=blue]
> Well a value in an object is
> an interpretation of a bit pattern
> according to the rules of a type
> - if you have no type you can't represent values.[/color]
*Until* you have a type, you can't represent values.
malloc returns the address of an object with indeterminate value.
--
pete
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
On Sat, 11 Jun 2005 23:44:45 +0000, pete wrote:
[color=blue]
> Lawrence Kirby wrote:
>[color=green]
>> Note that in the description above there is no
>> such thing in C as a "byte
>> object" (objects always have a type),
>> a char object is a byte *sized* object.[/color]
>
> An allocated object doesn't always have a type.[/color]
An allocated object is a grey area. The definition of the term "object"
says it is a region of data storage then contents of which can represent
values. Well a value in an object is an interpretation of a bit pattern
according to the rules of a type - if you have no type you can't represent
values.
Lawrence
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Mark McIntyre wrote:[color=blue]
>
> On Sat, 11 Jun 2005 23:44:45 GMT, in comp.lang.c , pete
> <pfiland@mindsp ring.com> wrote:
>[color=green]
> >Lawrence Kirby wrote:
> >[color=darkred]
> >> Note that in the description above there is no
> >> such thing in C as a "byte
> >> object" (objects always have a type),
> >> a char object is a byte *sized* object.[/color]
> >
> >An allocated object doesn't always have a type.[/color]
>
> Can you provide an example?[/color]
/* BEGIN new.c */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
void *pointer;
pointer = malloc(1);
printf("If %p", pointer);
puts(
" isn't a null pointer, then it's the address of an\n"
"allocated object that doesn't have a type."
);
free(pointer);
return 0;
}
/* END new.c */
--
pete
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Mark McIntyre <markmcintyre@s pamcop.net> writes:
[color=blue]
> On Sat, 11 Jun 2005 23:44:45 GMT, in comp.lang.c , pete
> <pfiland@mindsp ring.com> wrote:
>[color=green]
>>An allocated object doesn't always have a type.[/color]
>
> Can you provide an example?[/color]
The object that a non-null pointer returned by malloc() points to
initially has no type.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
On Sat, 11 Jun 2005 23:44:45 GMT, in comp.lang.c , pete
<pfiland@mindsp ring.com> wrote:
[color=blue]
>Lawrence Kirby wrote:
>[color=green]
>> Note that in the description above there is no
>> such thing in C as a "byte
>> object" (objects always have a type),
>> a char object is a byte *sized* object.[/color]
>
>An allocated object doesn't always have a type.[/color]
Can you provide an example?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Lawrence Kirby wrote:
[color=blue]
> Note that in the description above there is no
> such thing in C as a "byte
> object" (objects always have a type),
> a char object is a byte *sized* object.[/color]
An allocated object doesn't always have a type.
--
pete
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
On Mon, 06 Jun 2005 19:28:04 -0400, Joe Wright wrote:
[color=blue]
> Richard Bos wrote:[color=green]
>> Joe Wright <joewwright@com cast.net> wrote:
>>
>>[color=darkred]
>>>Joona I Palaste wrote:
>>>
>>>>pete <pfiland@mindsp ring.com> scribbled the following:
>>>>
>>>>
>>>>>A byte is a unit of memory.
>>>>>char is an object type.
>>>>
>>>>In the context of the C programming language, "byte" and "char" are the
>>>>same thing. In other contexts they might be different.
>>>
>>>I agree. Now if we can get Chris Torek to agree ..[/color]
>>
>>
>> Well, if you're being picky, pete is right: char is a basic object type;
>> a byte is the amount of memory that one object of type char takes.
>>
>> Richard[/color]
>
> Maybe a difference without a distinction. The term char is a C language
> thing and the term byte is more generic, having to do with memory size
> and disk size, etc. For most practical purposes the C char type
> describes a byte object in memory and on disk. Some might suggest a
> difference between a char object and a byte object. I am not one of them.[/color]
As the standard defines them char is a type and byte is a typeless unit of
memory allocation. Although strongly related (character types are defined
to have a size of 1 byte) they are different concepts.
Note that in the description above there is no such thing in C as a "byte
object" (objects always have a type), a char object is a byte *sized*
object.
Lawrence
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Richard Bos wrote:[color=blue]
> Joe Wright <joewwright@com cast.net> wrote:
>
>[color=green]
>>Joona I Palaste wrote:
>>[color=darkred]
>>>pete <pfiland@mindsp ring.com> scribbled the following:
>>>
>>>
>>>>A byte is a unit of memory.
>>>>char is an object type.
>>>
>>>In the context of the C programming language, "byte" and "char" are the
>>>same thing. In other contexts they might be different.[/color]
>>
>>I agree. Now if we can get Chris Torek to agree ..[/color]
>
>
> Well, if you're being picky, pete is right: char is a basic object type;
> a byte is the amount of memory that one object of type char takes.
>
> Richard[/color]
Maybe a difference without a distinction. The term char is a C language
thing and the term byte is more generic, having to do with memory size
and disk size, etc. For most practical purposes the C char type
describes a byte object in memory and on disk. Some might suggest a
difference between a char object and a byte object. I am not one of them.
--
Joe Wright mailto:joewwrig ht@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Joe Wright <joewwright@com cast.net> wrote:
[color=blue]
> Joona I Palaste wrote:[color=green]
> > pete <pfiland@mindsp ring.com> scribbled the following:
> >[color=darkred]
> >>A byte is a unit of memory.
> >>char is an object type.[/color]
> >
> > In the context of the C programming language, "byte" and "char" are the
> > same thing. In other contexts they might be different.[/color]
>
> I agree. Now if we can get Chris Torek to agree ..[/color]
Well, if you're being picky, pete is right: char is a basic object type;
a byte is the amount of memory that one object of type char takes.
Richard
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Joona I Palaste wrote:[color=blue]
> pete <pfiland@mindsp ring.com> scribbled the following:
>[color=green]
>>Ari Lukumies wrote:
>>[color=darkred]
>>>Martin Ambuhl wrote:
>>>
>>>>cpptutor200 0@yahoo.com wrote:
>>>>
>>>>>Could some C guru help me please? A byte is an unsigned char in C.
>>>>
>>>>No, 'byte' is a synonym for 'char', which may be either signed or
>>>>unsigned. An unsigned byte is an unsigned char.
>>>>Whether there is any
>>>>type that corresponds to, for example, an octet depends upon the
>>>>implementat ion.
>>>
>>>What? Have I been away too long? I thought that a char is an entity
>>>of value, but not necessarily one that resembles a byte. Maybe
>>>I've missed a standard... :D[/color][/color]
>
>[color=green]
>>A byte is a unit of memory.
>>char is an object type.[/color]
>
>
> In the context of the C programming language, "byte" and "char" are the
> same thing. In other contexts they might be different.
>[/color]
I agree. Now if we can get Chris Torek to agree ..
--
Joe Wright mailto:joewwrig ht@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
pete <pfiland@mindsp ring.com> scribbled the following:[color=blue]
> Ari Lukumies wrote:[color=green]
>> Martin Ambuhl wrote:[color=darkred]
>> > cpptutor2000@ya hoo.com wrote:
>> >> Could some C guru help me please? A byte is an unsigned char in C.
>> >
>> > No, 'byte' is a synonym for 'char', which may be either signed or
>> > unsigned. An unsigned byte is an unsigned char.
>> > Whether there is any
>> > type that corresponds to, for example, an octet depends upon the
>> > implementation.[/color]
>>
>> What? Have I been away too long? I thought that a char is an entity
>> of value, but not necessarily one that resembles a byte. Maybe
>> I've missed a standard... :D[/color][/color]
[color=blue]
> A byte is a unit of memory.
> char is an object type.[/color]
In the context of the C programming language, "byte" and "char" are the
same thing. In other contexts they might be different.
--
/-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"C++ looks like line noise."
- Fred L. Baube III
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Ari Lukumies wrote:[color=blue]
>
> Martin Ambuhl wrote:[color=green]
> > cpptutor2000@ya hoo.com wrote:
> >[color=darkred]
> >> Could some C guru help me please? A byte is an unsigned char in C.[/color]
> >
> > No, 'byte' is a synonym for 'char', which may be either signed or
> > unsigned. An unsigned byte is an unsigned char.
> > Whether there is any
> > type that corresponds to, for example, an octet depends upon the
> > implementation.[/color]
>
> What? Have I been away too long? I thought that a char is an entity
> of value, but not necessarily one that resembles a byte. Maybe
> I've missed a standard... :D[/color]
A byte is a unit of memory.
char is an object type.
--
pete
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Ari Lukumies wrote:[color=blue]
> Martin Ambuhl wrote:
>[color=green]
>> cpptutor2000@ya hoo.com wrote:
>>[color=darkred]
>>> Could some C guru help me please? A byte is an unsigned char in C.[/color]
>>
>>
>> No, 'byte' is a synonym for 'char', which may be either signed or
>> unsigned. An unsigned byte is an unsigned char. Whether there is any
>> type that corresponds to, for example, an octet depends upon the
>> implementation.[/color]
>
>
> What? Have I been away too long? I thought that a char is an entity
> of value, but not necessarily one that resembles a byte. Maybe
> I've missed a standard... :D[/color]
I have no idea what you think you said. A byte and a char are the same
by definition in C, and has been for 16 years, so you've missed not *a*
standard, but *every* standard.
Here's what a char is (3.1.2.5 in C89)
An object declared as type char is large enough to store any member
of the basic execution character set. If a member of the required
source character set enumerated in $2.2.1 is stored in a char object,
its value is guaranteed to be positive. If other quantities are
stored in a char object, the behavior is implementation-defined: the
values are treated as either signed or nonnegative integers.
Here's what a byte is (1.6 in C89)
* Byte --- the unit of data storage in the execution environment
large enough to hold any member of the basic character set of the
execution environment. It shall be possible to express the address of
each individual byte of an object uniquely. A byte is composed of a
contiguous sequence of bits, the number of which is
implementation-defined. The least significant bit is called the
low-order bit; the most significant bit is called the high-order bit.
and if that's not clear, note from the language for sizeof (3.3.3.4);
The sizeof operator yields the size (in bytes) of its operand, ...
When applied to an operand that has type char , unsigned char , or
signed char , (or a qualified version thereof) the result is 1
Leave a comment:
-
Guest repliedRe: HELP PLEASE - How to convert string to byte array
Martin Ambuhl wrote:[color=blue]
> cpptutor2000@ya hoo.com wrote:
>[color=green]
>> Could some C guru help me please? A byte is an unsigned char in C.[/color]
>
> No, 'byte' is a synonym for 'char', which may be either signed or
> unsigned. An unsigned byte is an unsigned char. Whether there is any
> type that corresponds to, for example, an octet depends upon the
> implementation.[/color]
What? Have I been away too long? I thought that a char is an entity
of value, but not necessarily one that resembles a byte. Maybe
I've missed a standard... :D
-atl-
--
A multiverse is figments of its own creations
Leave a comment:
Leave a comment: