Re: variable sized unions
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 03 Nov 2005 03:02:32 GMT
"lyrx" <vijju.singh@xxxxxxxxx> writes:
> Hello. I have some legacy code which has
>
> union x {
> struct y;
> char z[64*1024];
> }
>
> I would like to change this to a variable sized union.
>
> I tried
>
> union x {
> struct y;
> char *z;
> }
>
> allocated 2k of memory, and cast it to this union. The code does not
> work. I just wanted to know if I was doing something that is not
> supposed to work.
Arrays and pointers are two entirely different things. Given "char *z",
for z to be valid it has to point to some valid chunk of memory,
either an object or a chunk allocated with malloc().
What exactly are you trying to accomplish?
You might find section 6 of the comp.lang.c FAQ, "Arrays and
Pointers", useful.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: variable sized unions
- From: Christopher Benson-Manica
- Re: variable sized unions
- References:
- variable sized unions
- From: lyrx
- variable sized unions
- Prev by Date: Re: scanf to handle double
- Next by Date: Re: beginner c questions
- Previous by thread: Re: variable sized unions
- Next by thread: Re: variable sized unions
- Index(es):
Relevant Pages
|