Re: pointer q
- From: RSoIsCaIrLiIoA <zz@xxxx>
- Date: Mon, 15 May 2006 10:08:47 +0200
On Sun, 14 May 2006 08:48:41 -0400, Eric Sosman
<esosman@xxxxxxxxxxxxxxxxxxx> wrote:
Joe Smith wrote:
"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:lnlkt5bqv3.fsf@xxxxxxxxxxxxxxxxxx
"Joe Smith" <grumpy196884@xxxxxxxxxxx> writes:
A recent post of mine showed a sufficiently large gaffe on pointers as to
need to return to K&R 5.1-6 appendix A8.6.1 . So we have type
specifiers:
int
long
. One dreams himself variable names: qwe, qwr, writes
int qwe;
long qwr;
and thinks he knows what types he's declared. Had you asked me about:
int *qwe;
long *qwr;
I would have said the pointers declared were--while pointng to different
types--of the same type. Why am I wrong? Joe
int* and long* are two different types (both pointer types).
I'm curious, what led you to think that they're the same type?
What's to stop me from swapping an int * and a long *? Joe
Assume sizeof(int) < sizeof(long), and consider
long l = 42;
int *ip = &l; /* illegal, but Let's Pretend */
*ip = 76;
What value is now stored in `l'?
That's why int* and long* aren't interchangeable.
and so where is the problem?
the problem is different cpus store data in different ways
here
#include <stdio.h>
int main ( void )
{int l = 42;
short *ip = &l; /* illegal, but Let's Pretend */
*ip = 76;
printf(" sizeof(short)==%u sizeof(int)==%u \n",
(unsigned) sizeof(short), (unsigned) sizeof(int));
printf("l==%d\n", l);
return 0;
}
sizeof(short)==2 sizeof(int)==4
l==76
all ok
the problem is "it is easy to obfuscate and make difficult
what it is easy" and it is in the cpu design
another example could be why not exchange "str* and sprintf, etc"
with a secure
int s?prinf(char* strig, int size_of_string, char* fmt, ...);?
because it is easier "to do difficult what is easy" then
Bugtraq is full of error for the C language
.
- Follow-Ups:
- Re: pointer q
- From: Joe Smith
- Re: pointer q
- References:
- pointer q
- From: Joe Smith
- Re: pointer q
- From: Keith Thompson
- Re: pointer q
- From: Joe Smith
- Re: pointer q
- From: Eric Sosman
- pointer q
- Prev by Date: Re: Listing the most dangerous parts of C
- Next by Date: Re: short or int
- Previous by thread: Re: pointer q
- Next by thread: Re: pointer q
- Index(es):
Relevant Pages
|