Re: integer to pinter conversion
- From: junky_fellow@xxxxxxxxxxx
- Date: 15 Sep 2005 03:13:43 -0700
Jack Klein wrote:
> On Wed, 14 Sep 2005 09:37:14 +0200, Irrwahn Grausewitz
> <irrwahn35@xxxxxxxxxx> wrote in comp.lang.c:
>
> > junky_fellow@xxxxxxxxxxx wrote:
> > >Consider a function:
> > >
> > >void *test_func(void)
> > >{
> > > return ((void *)-1);
> > >}
> > >
> > >While returning, the integer -1 is converted to void *.
> > >Is this portable ?
> >
> > No. While an integer may be converted to a pointer, the result
> > of this conversion is implementation-defined, with the obvious
> > exception of an integer constant expression with the value 0.
> >
> > FWIW, you don't even need the cast in the code above.
>
> I beg to differ. With the exception of an integer constant expression
> evaluating to 0 (i.e., special case to initialize/set a pointer to
> NULL), a cast is required to convert between an integer type and a
> pointer type. Regardless of whether that is in an initialization,
> assignment, or passing as a parameter or returning. The latter two
> are performed "as if by assignment" anyway.
>
Since the return type is void *, so if the function func() returns
-1, will the compiler not convert the integer to void * even if
the cast is not applied ? I get a warning without the cast, but the
conversion is still being done.
.
- Follow-Ups:
- Re: integer to pinter conversion
- From: Lawrence Kirby
- Re: integer to pinter conversion
- References:
- integer to pinter conversion
- From: junky_fellow
- Re: integer to pinter conversion
- From: Irrwahn Grausewitz
- Re: integer to pinter conversion
- From: Jack Klein
- integer to pinter conversion
- Prev by Date: Re: Getting a pointer to a variable by its name as a string
- Next by Date: Making a lite version
- Previous by thread: Re: integer to pinter conversion
- Next by thread: Re: integer to pinter conversion
- Index(es):
Relevant Pages
|