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

char vs int

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ
Nov 14 '05 #1
28 2662


Merrill & Michele wrote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
Check the return value of malloc. Always.
strcpy(p, "tja");
To be on the safe side, you could for example do
*p = '\0';
strncat(p,"tja",4-1);
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ


p is a char *. It is definitely not a char or int.
Please follow the simple rule of rereading your message
before you send it as we otherwise have to guess what
you could have meant apart from the on average high
level of weirdness by which many of your messages are
permeated.

My guess is:
"character constants are of type int and many functions
return int/have int parameters when we are dealing with
single characters -- why is it then that we store strings
in char arrays or memory pointed to by char * variables?"

Is that your question?
For that I have an answer.
-Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2

"Merrill & Michele" <be********@comcast.net> wrote in message
news:yr********************@comcast.com...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ


Becuase you are copying a char-array into it using a function which requires
a char*?
Nov 14 '05 #3
Merrill & Michele wrote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ

Cause you, the programmer, made it a char pointer.
Which seems good, as you're coping a C string to it,
and strings are usually best manipulated as sequences
of chars, it is also what "%s" in your printf statement
would expect..
Nov 14 '05 #4
On Wed, 17 Nov 2004 08:40:20 -0600, Merrill & Michele wrote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ


p is a pointer to char, not a char, and this is because that is how you
defined it, why in the world would you expect it to be an int??

Rob Gamble
Nov 14 '05 #5
Merrill & Michele wrote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ


Are you asking why chars are stored in variables of type char?
And p is not a char.

Honestly, I usually try to give the questioner the benefit of the doubt
and I apply a good amount of charity of interpretation, but your
question does not make sense to me. I cannot even tell if you saying
that p is of type char is a mistake or ignorance on your part.

Please tell us why you think p could have been an int (or probably
pointer to int) instead of a pointer to char. Are you by any chance
referring to the fact that getchar and getc returns ints and not chars?
(So you see, I might be beginning to understand your question after all
though I didn't when I wrote the previous paragraph. But still I need
you to ask it.)

--
Thomas.
Nov 14 '05 #6
"Merrill & Michele" <be********@comcast.net> wrote:
<Snip>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja"); <Snip>
Why is p a char and not an int? MPJ


I am going to assume that you are asking the following question.

Why do we store strings in arrays of char data types instead of arrays of
int data types?

Well I would answer that int data types while capable of holding the same
information as a char data type while doing so they are wasting X bytes of
space (size of X depends on the number of bytes in an int on the system
though on most 32 bit machines it is 4 bytes in length so there are 3 bytes
wasted.)

While this doesn't seem like much how about if you have a string buffer that
needs to store a 1024 characters. This would take up 1Kb of space using an
array of char data types but 4Kb of space (on most 32 bit machines again)
if it was using int data types.

If that is not your question then please repost with a clarified version and
I will have another go.
--------------
Jason Cooper
Nov 14 '05 #7

"J.L.Cooper" <A@A.COM> wrote in message
news:cn**********@sun-cc204.lut.ac.uk...
"Merrill & Michele" <be********@comcast.net> wrote:
<Snip>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja"); <Snip>

Why is p a char and not an int? MPJ


I am going to assume that you are asking the following question.

Why do we store strings in arrays of char data types instead of arrays of
int data types?

Well I would answer that int data types while capable of holding the same
information as a char data type while doing so they are wasting X bytes of
space (size of X depends on the number of bytes in an int on the system
though on most 32 bit machines it is 4 bytes in length so there are 3

bytes wasted.)

While this doesn't seem like much how about if you have a string buffer that needs to store a 1024 characters. This would take up 1Kb of space using an array of char data types but 4Kb of space (on most 32 bit machines again)
if it was using int data types.

If that is not your question then please repost with a clarified version and I will have another go.
--------------
Jason Cooper

Thanks all for replies. That I thought I had partitioned the choice of data
type in this question with int and char shows exactly what I don't
understand. I'll hit K&R and the FAQs and get back to you. MPJ
Nov 14 '05 #8
In <30*************@uni-berlin.de> Michael Mair <Mi**********@invalid.invalid> writes:


Merrill & Michele wrote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);


Check the return value of malloc. Always.


That's good advice for code that is meant to be executed. It's bad advice
for code that is meant to merely illustrate a point, because the error
checking code distracts the reader from the real purpose of the code.
strcpy(p, "tja");


To be on the safe side, you could for example do
*p = '\0';
strncat(p,"tja",4-1);


It's not any safer than the original, but it is less readable and has
higher maintenance overhead (the magical constant 4 appears in two places
instead of one).

Even in more complex examples, it is open to debate whether this is the
right thing to do: silently generating the *wrong* result is seldom a
better option than reporting an error. That's why strncat is seldom used
as a "safe" strcpy.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #9
> >[OP: Why is a char * a char and not an int]
Michael Mair: [insult snipped] My guess is:
"character constants are of type int and many functions
return int/have int parameters when we are dealing with
single characters -- why is it then that we store strings
in char arrays or memory pointed to by char * variables?"
Is that your question?
For that I have an answer I would imagine that your answer is similar to K&R §5.5 . But since I don't
get it, I would welcome the answer to that question.
Nils Selasdal:
Cause you, the programmer, made it a char pointer.
Which seems good, as you're cop[y]ing a C string to it,
and strings are usually best manipulated as sequences
of chars, it is also what "%s" in your printf statement
would expect..


K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


Nov 14 '05 #10

"Thomas Stegen" <th***********@gmail.com> wrote in message
news:30*************@uni-berlin.de...
Merrill & Michele wrote:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char *p;
p=malloc(4);
strcpy(p, "tja");
printf("%s\n", p);
free(p);
return 0;
}

Why is p a char and not an int? MPJ

Are you asking why chars are stored in variables of type char?
And p is not a char.

Honestly, I usually try to give the questioner the benefit of the doubt
and I apply a good amount of charity of interpretation, but your
question does not make sense to me. I cannot even tell if you saying
that p is of type char is a mistake or ignorance on your part.


Don't underestimate my ability to be simultaneously mistaken and ignorant.
Please tell us why you think p could have been an int (or probably
pointer to int) instead of a pointer to char. Are you by any chance
referring to the fact that getchar and getc returns ints and not chars?
(So you see, I might be beginning to understand your question after all
though I didn't when I wrote the previous paragraph. But still I need
you to ask it.)


I think you're getting at one aspect of my confusion. MPJ
..
Nov 14 '05 #11

Merrill & Michele wrote:
[OP: Why is a char * a char and not an int]
Michael Mair:
"character constants are of type int and many functions
return int/have int parameters when we are dealing with
single characters -- why is it then that we store strings
in char arrays or memory pointed to by char * variables?"
Is that your question?
For that I have an answer


I would imagine that your answer is similar to K&R §5.5 .
But since I don't get it, I would welcome the answer to
that question.


It has been answered by others in this thread. So, here's
the short of it:
- 'a' is a character constant. A variable of type char can
hold a variable constant. The constant itself could also
be (in a non-portable way) expressed as a number in the
range [CHAR_MIN,...,CHAR_MAX]. Integer constants without
u/U, l/L or a combination are considered to be of type int.
- As characters and character constants can be (from the
C type point of view) most efficiently be stored in
char variables, we use char arrays to store more than one
of them instead of int arrays. If there is a value 0 in
this char array, we have a C string (terminated by 0, or
'\0' if you like that better).
- We only talk of "strings" if the array is a char array.
- Functions dealing with strings expect dealing with char
arrays or memory areas pointed to by char *.

Nils Selasdal:
Cause you, the programmer, made it a char pointer.
Which seems good, as you're cop[y]ing a C string to it,
and strings are usually best manipulated as sequences
of chars, it is also what "%s" in your printf statement
would expect..


K&R §2.2: "There are only a few basic data types in C:

^^^^^ char, int, float, double."
Is char * a data type? How about int **? MPJ


Yes. 'Tis.
You seem to have problems wrapping your mind around the
concept of pointers. Is this right?
If no, are you comfortable with the relationship between
pointers and arrays? Else: What do you think an array is?
Do you understand why there is a difference between
passing a variable's value or its adress?

If your actual problem is with pointers, you should try
to pin down your difficulties, have a peek at the FAQ
(most people think along similar lines when it comes
to misunderstanding pointers), reread the chapter in K&R
and come back here to ask the questions left.
Please formulate them in a succinct but precise way (if
necessary, do a definition of terms first).
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #12

Merrill & Michele wrote:
[OP: Why is a char * a char and not an int]
Michael Mair:
"character constants are of type int and many functions
return int/have int parameters when we are dealing with
single characters -- why is it then that we store strings
in char arrays or memory pointed to by char * variables?"
Is that your question?
For that I have an answer

I would imagine that your answer is similar to K&R §5.5 .
But since I don't get it, I would welcome the answer to
that question.


It has been answered by others in this thread. So, here's
the short of it:
- 'a' is a character constant. A variable of type char can
hold a character constant. The constant itself could also
be (in a non-portable way) expressed as a number in the
range [CHAR_MIN,...,CHAR_MAX]. Integer constants without
u/U, l/L or a combination are considered to be of type int.
- As characters and character constants can be (from the
C type point of view) most efficiently be stored in
char variables, we use char arrays to store more than one
of them instead of int arrays. If there is a value 0 in
this char array, we have a C string (terminated by 0, or
'\0' if you like that better).
- We only talk of "strings" if the array is a char array.
- Functions dealing with strings expect dealing with char
arrays or memory areas pointed to by char *.

Nils Selasdal:
Cause you, the programmer, made it a char pointer.
Which seems good, as you're cop[y]ing a C string to it,
and strings are usually best manipulated as sequences
of chars, it is also what "%s" in your printf statement
would expect..

K&R §2.2: "There are only a few basic data types in C:


^^^^^ char, int, float, double." Is char * a data type? How about int **? MPJ

Yes. 'Tis.
You seem to have problems wrapping your mind around the
concept of pointers. Is this right?
If no, are you comfortable with the relationship between
pointers and arrays? Else: What do you think an array is?
Do you understand why there is a difference between
passing a variable's value or its adress?

If your actual problem is with pointers, you should try
to pin down your difficulties, have a peek at the FAQ
(most people think along similar lines when it comes
to misunderstanding pointers), reread the chapter in K&R
and come back here to ask the questions left.
Please formulate them in a succinct but precise way (if
necessary, do a definition of terms first).
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #13
On Thu, 18 Nov 2004 10:23:15 -0600, Merrill & Michele wrote:

....
K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


char * is a data type, but it is a derived type, not a basic type. char *
is derived from char. int ** is derived from int * which in turn is
derived from int.

Lawrence
Nov 14 '05 #14
"Merrill & Michele" <be********@comcast.net> wrote in message
news:lN********************@comcast.com...
K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


Yes, they both are types, but not 'basic types'.
They are 'derived types'.

See ISO 9899:1999 6.2.5/14 and 6.2.5/20
-MIke
Nov 14 '05 #15

"Michael Mair" <Mi**********@invalid.invalid> wrote in message
news:30*************@uni-berlin.de...

Merrill & Michele wrote:
>>> [OP: Why is a char * a char and not an int]

> K&R §2.2: "There are only a few basic data types in C:
^^^^^
> char, int, float, double."

> Is char * a data type? How about int **? MPJ

Yes. 'Tis.


Your posts were identical to my eye. Am I right to think that the four
basic data types followed by any number of asterisks are unique data types?
E.g. int * is as different from int *** as a char is from a double.
You seem to have problems wrapping your mind around the
concept of pointers. Is this right?
I can't wrap my mind around a lot of things, e.g. how airfoil can lift
something like a tank, yet I fly. The problem with the K&R development
right now is that everything has to come together. I think it's more to the
point that I'm simultaneously struggling with functions. What I'd like to
do is revisit the derangement code but with the static int myrand that you
suggested. I'll have to find a hard copy of it. That I can't follow
program control through these calls is a serious hurdle.
If no, are you comfortable with the relationship between
pointers and arrays? Else: What do you think an array is?
Do you understand why there is a difference between
passing a variable's value or its adress?
o.k. on all that for the time being. That's a Fehlleistung on the spelling
of Anschrift.
If your actual problem is with pointers, you should try
to pin down your difficulties, have a peek at the FAQ
(most people think along similar lines when it comes
to misunderstanding pointers), reread the chapter in K&R
and come back here to ask the questions left.
Please formulate them in a succinct but precise way (if
necessary, do a definition of terms first).


I spent two hours in the FAQs today, one hour in K&R, and it's noon. I'm
going to see if I can find the answer at the watering hole. MPJ
Nov 14 '05 #16
Merrill & Michele wrote:

K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.

My guess is that one needs to read a little more of
K&R's context to understand what they mean by "basic."

--
Er*********@sun.com
Nov 14 '05 #17

"Eric Sosman" <er*********@sun.com> wrote in message
news:cn**********@news1brm.Central.Sun.COM...
Merrill & Michele wrote:

K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.

My guess is that one needs to read a little more of
K&R's context to understand what they mean by "basic."
You'd be stuck reading tea leaves with the K&R context here. short, long,
signed and unsigned are mentioned along with the basic data declarations,
but I have yet to stumble across a sentence that says, "well folks, chp. 2
is long behind us, and we're going to nuance this discussion of type." And
please don't ask me why Mr. Sosman's comments don't have arrows on them.
MPJ

Nov 14 '05 #18
Merrill & Michele wrote:

"Eric Sosman" <er*********@sun.com> wrote in message
news:cn**********@news1brm.Central.Sun.COM...
Merrill & Michele wrote:

K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.


void is an incomplete type, not an object type.

--
pete
Nov 14 '05 #19
On Thu, 18 Nov 2004 12:07:58 -0600, Merrill & Michele wrote:

....
Your posts were identical to my eye. Am I right to think that the four
basic data types followed by any number of asterisks are unique data types?
E.g. int * is as different from int *** as a char is from a double.


Yes int * and int *** are different types. You can't assign one to the
other and doing so wouldn't make a lot of sense. One can point to objects
of type int, the other to objects of type int **.

Lawrence

Nov 14 '05 #20
In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
"Eric Sosman" <er*********@sun.com> wrote in message
news:cn**********@news1brm.Central.Sun.COM...

Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.


void is an incomplete type, not an object type.


No one said it's an object type, but a valid, non-null void pointer
value can only be pointing to an object. Hence the weirdness of void.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #21
"Merrill & Michele" <be********@comcast.net> wrote in message news:<cd********************@comcast.com>...
"Eric Sosman" <er*********@sun.com> wrote in message
news:cn**********@news1brm.Central.Sun.COM...
Merrill & Michele wrote:

K&R §2.2: "There are only a few basic data types in C: char, int, float,
double."
Is char * a data type? How about int **? MPJ


Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.

My guess is that one needs to read a little more of
K&R's context to understand what they mean by "basic."
You'd be stuck reading tea leaves with the K&R context here. short, long,
signed and unsigned are mentioned along with the basic data declarations,
but I have yet to stumble across a sentence that says, "well folks, chp. 2
is long behind us, and we're going to nuance this discussion of type." And
please don't ask me why Mr. Sosman's comments don't have arrows on them.
MPJ

You might want to look at other references as well. My primary
reference is Harbison & Steele, and here's how they organize types:

Scalar Types
Arithmetic Types
Integral Types
short, int, long, long long (signed/unsigned)
char (signed/unsigned)
_Bool
enum {...}

Floating-point Types
float, double, long double
float _Complex, double _Complex, long double _Complex,
float _Imaginary, double _Imaginary,
long double _Imaginary

Pointer Types
T *

Aggregate Types
Array Types
T [...]

Structure Types
struct {...}

Union Types
union {...}

Function Types
T (...)

Void Type
void

H&S don't try to distinguish between "basic" and "derived" types, and
I'm not sure I could do so. I've never had to worry about it in the
past. I would imagine that enum, char, short, int, long, long long,
float, double, and long double are basic types; everything else
(pointers, arrays, structs, unions, etc.) is derived from those types.
Nov 14 '05 #22
On Thu, 18 Nov 2004 10:26:52 -0600, "Merrill & Michele"
<be********@comcast.net> wrote:
Don't underestimate my ability to be simultaneously mistaken and ignorant.


Grabbed. Generalized to be M&M corollary of Sprague's law.

Sprague's Law:
"There are three orders of magnitude more dumbshits in the world than
there can be any use for." --William Sprague

Quitt's Clarification to Sprague's Law:
"Stupid isn't not being smart; stupid is not using one's smarts."
--Kevin D. Quitt

The M&M corollary of Sprague's law:
"Don't underestimate the ability to be simultaneously mistaken and
ignorant." --Merrill & Michele

In answer to "How can people be so stupid as to...":
"We all do what we're good at." --Kevin D. Quitt
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 14 '05 #23

"John Bode" <jo*******@my-deja.com> wrote in message
news:43**************************@posting.google.c om...
"Merrill & Michele" <be********@comcast.net> wrote in message

news:<cd********************@comcast.com>...
"Eric Sosman" <er*********@sun.com> wrote in message
news:cn**********@news1brm.Central.Sun.COM...
Merrill & Michele wrote:

K&R §2.2: "There are only a few basic data types in C: char, int, float, double."
Is char * a data type? How about int **? MPJ


Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.

My guess is that one needs to read a little more of
K&R's context to understand what they mean by "basic."
You'd be stuck reading tea leaves with the K&R context here. short, long, signed and unsigned are mentioned along with the basic data declarations, but I have yet to stumble across a sentence that says, "well folks, chp. 2 is long behind us, and we're going to nuance this discussion of type." And please don't ask me why Mr. Sosman's comments don't have arrows on them.
MPJ

You might want to look at other references as well. My primary
reference is Harbison & Steele, and here's how they organize types:

Scalar Types
Arithmetic Types
Integral Types
short, int, long, long long (signed/unsigned)
char (signed/unsigned)
_Bool
enum {...}

Floating-point Types
float, double, long double
float _Complex, double _Complex, long double _Complex,
float _Imaginary, double _Imaginary,
long double _Imaginary

Pointer Types
T *

Aggregate Types
Array Types
T [...]

Structure Types
struct {...}

Union Types
union {...}

Function Types
T (...)

Void Type
void

H&S don't try to distinguish between "basic" and "derived" types, and
I'm not sure I could do so. I've never had to worry about it in the
past. I would imagine that enum, char, short, int, long, long long,
float, double, and long double are basic types; everything else
(pointers, arrays, structs, unions, etc.) is derived from those types.

I'm due to spend another $50 on a C book. Since H&S is referenced in the
FAQs, I'll go with that. MPJ
Nov 14 '05 #24

"Kevin D. Quitt" <KQ**********@IEEIncUNMUNG.com> wrote in message
news:6q********************************@4ax.com...
On Thu, 18 Nov 2004 10:26:52 -0600, "Merrill & Michele"
<be********@comcast.net> wrote:
Don't underestimate my ability to be simultaneously mistaken and
ignorant.
Grabbed. Generalized to be M&M corollary of Sprague's law.

Sprague's Law:
"There are three orders of magnitude more dumbshits in the world than
there can be any use for." --William Sprague

Quitt's Clarification to Sprague's Law:
"Stupid isn't not being smart; stupid is not using one's smarts."
--Kevin D. Quitt

The M&M corollary of Sprague's law:
"Don't underestimate the ability to be simultaneously mistaken and
ignorant." --Merrill & Michele

In answer to "How can people be so stupid as to...":
"We all do what we're good at." --Kevin D. Quitt
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list

Many people might find uncomfortable having one's shortcomings turned into a
"law." I like to think of it as being unafraid to leave my zone of comfort
to try a new dance. MPJ
Nov 14 '05 #25
Merrill & Michele <be********@comcast.net> scribbled the following:
"Kevin D. Quitt" <KQ**********@IEEIncUNMUNG.com> wrote in message
news:6q********************************@4ax.com...

--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list

Many people might find uncomfortable having one's shortcomings turned into a
"law." I like to think of it as being unafraid to leave my zone of comfort
to try a new dance. MPJ


Please snip away other people's signatures before replying, or reply
between the content and the signature. The way you did it, your reply
appears as part of Kevin's signature.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
Nov 14 '05 #26
Dan Pop wrote:

In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
"Eric Sosman" <er*********@sun.com> wrote in message
news:cn**********@news1brm.Central.Sun.COM...

Those are "derived type," as others have mentioned.
But what about `short int', `long int', and `long double'?
And then there are the `unsigned' variants ... Despite
the multi-word names, these are in no sense "derived"
types. Finally there's `void' -- which might be excluded
from the ranks of "data types" by virtue of its weirdness.
void is an incomplete type, not an object type.


No one said it's an object type,


That's why I said it.
OP listed some object types and mentioned their variants
and then mused about why void was different.
but a valid, non-null void pointer
value can only be pointing to an object. Hence the weirdness of void.


All pointers to incomplete types are like that.
Incomplete types don't have values and
pointers to incomplete types don't have arithmetic.

--
pete
Nov 14 '05 #27
pete wrote:

Dan Pop wrote:

In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
> "Eric Sosman" <er*********@sun.com> wrote in message
> news:cn**********@news1brm.Central.Sun.COM...
>
> Those are "derived type," as others have mentioned.
> But what about `short int', `long int', and `long double'?
> And then there are the `unsigned' variants ... Despite
> the multi-word names, these are in no sense "derived"
> types. Finally there's `void' -- which might be excluded
> from the ranks of "data types" by virtue of its weirdness.

void is an incomplete type, not an object type.


No one said it's an object type,


That's why I said it.


That's why I said what I said: that it's an incomplete type.

--
pete
Nov 14 '05 #28
In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
Dan Pop wrote:

In <41***********@mindspring.com> pete <pf*****@mindspring.com> writes:
>> "Eric Sosman" <er*********@sun.com> wrote in message
>> news:cn**********@news1brm.Central.Sun.COM...
>>
>> Those are "derived type," as others have mentioned.
>> But what about `short int', `long int', and `long double'?
>> And then there are the `unsigned' variants ... Despite
>> the multi-word names, these are in no sense "derived"
>> types. Finally there's `void' -- which might be excluded
>> from the ranks of "data types" by virtue of its weirdness.
>
>void is an incomplete type, not an object type.
No one said it's an object type,


That's why I said it.


So, you're talking out of context.
OP listed some object types and mentioned their variants
and then mused about why void was different.
but a valid, non-null void pointer
value can only be pointing to an object. Hence the weirdness of void.
All pointers to incomplete types are like that.


Yes, but void is, by far, the most important incomplete type. Few
programs use other incomplete types or pointers to them.
Incomplete types don't have values and
pointers to incomplete types don't have arithmetic.


GNU C defines pointer arithmetic on void pointers and this is a fairly
useful feature. Too bad it was ignored by the C standardisation process.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #29

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

Similar topics

9
by: Christopher Benson-Manica | last post by:
I need a smart char * class, that acts like a char * in all cases, but lets you do some std::string-type stuff with it. (Please don't say to use std::string - it's not an option...). This is my...
5
by: Alex Vinokur | last post by:
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message news:4180f756.197032434@news.individual.net... to news:comp.lang.c > ben19777@hotmail.com (Ben) wrote: > > 2) Structure casted into an...
5
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file and copies the contents into the two char*s. Now...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
4
by: Paul Brettschneider | last post by:
Hello all, consider the following code: typedef char T; class test { T *data; public: void f(T, T, T); void f2(T, T, T);
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.