l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
December 2: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2006 Jun 04 16:40

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] C - passing chars and pointer to chars
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] C - passing chars and pointer to chars



On Sun, Jun 04, 2006 at 10:05:22AM -0400, Peter Jay Salzman wrote:
> I gave good reasons *why* passing the pointers should always work.  I think
> Micah really got at the heart of the matter:
> 
> 
>    Micah said:
>    Pointers to incompatible types are not guaranteed to be represented the
>    same way, even though in practice they are. /All/ pointer types must be
>    convertible to and from a pointer to any character type, and used as
>    such, so this makes it all the more likely that they will be represented
>    the same.
> 
>    Irregardless, the Standard does /require/ that a warning be given when
>    you try to do this.
> 
> 
> I think the  main point is the lack of guarantee that they're represented
> the same way.  Here's what I think he means.
> 
> I *think* what Micah is saying here is that even though a char and signed
> char types have the same width (1 byte) and are implemented the same way in
> practise, there's no guarantee that they *are* implemented the same way.

Actually, no: char and signed char /must/ be represented the same way,
if char is signed.

> For example, a perverse compiler writer may put a byte of dead storage (for
> whatever reason) in between contiguous elements of a char array and 2 bytes
> of dead storage in between contiguous elements of a signed char array.

Well, no, it couldn't. At the very least, you must be able to convert a
pointer to /anything/ to a pointer to character type, and be able to
inspect the byte values in that way.

I was actually talking about the fact that the /pointer/ types don't
have to be represented the same way. A compiler could represent signed
char pointers as a value bit-shifted two to the left, whereas a pointer
to char could be a bitwise complement of the same value. Not likely, but
basically, the Standard committee don't want you just passing stuff
around in general without first declaring, "I know what the hell I'm
doing" (via a cast).

-- 
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.