Re: why is casting malloc a bad thing?

From: Michael Wojcik (mwojcik_at_newsguy.com)
Date: 01/26/04


Date: 26 Jan 2004 21:11:41 GMT


In article <hqEQb.4916$qA4.1039@nwrddc01.gnilink.net>, "P.J. Plauger" <pjp@dinkumware.com> writes:
> "Mark McIntyre" <markmcintyre@spamcop.net> wrote in message
> news:svq510hmo8tlllf4she80nd170peljhdkv@4ax.com...
>
> > On Sat, 24 Jan 2004 19:00:24 GMT, in comp.lang.c , "P.J. Plauger"
> > <pjp@dinkumware.com> wrote:
> >
> > >"Jack Klein" <jackklein@spamcop.net> wrote in message
> > >news:c2e510h9hbjao7qn7uo5v4h3c7kgipak6s@4ax.com...
> > >
> > >> > warning: invalid conversion from `void*' to `double*'
> > >>
> > >> This is comp.lang.c, there is no such thing as an invalid conversion
> > >> from void* to double*. The conversion is implicit and correct.
> > >
> > > If the alignment is incorrect the conversion is invalid.
> >
> > But its impossible for it to be incorrect. The C Standard says so. If
> > your h/w platform can't guarantee it, then you can't implement C
> > there.
>
> Next step after nonsense -- bullshit. See 6.3.2.3, para. 7.

I suspect Mark thought you were claiming that a (non-null) void *
value *returned by malloc* could point to an area that was
incorrectly aligned for double. Of course a void * value obtained
another way (from the address of a pointer to a different type, or
from an uninitialized automatic void* variable, and so forth) may
point to such an area, and assigning such a value to a double* would
be invalid.

I also suspect Mark did not recognize your name, or he might have
double-checked before posting.

Of course, my suspicions may be ill-founded.

-- 
Michael Wojcik                  michael.wojcik@microfocus.com
Do not "test" parts, as this may compromise sensitive joinery.  Those who
suffer difficulty should abandon the enterprise immediately.  -- Chris Ware


Relevant Pages

  • Re: help w/ c/c++ problem
    ... clarify the above, since you've seen fit to complain about it. ... A conforming implementation may allow 'void main' ... you too are incorrect since you need to add the words "provided it ...
    (comp.lang.c)
  • Re: Copy Constructors and Assignment Operator, When should I use?
    ... the erased element, so the above is incorrect. ... void removeFstItem{ ... vecItr!= m_vecB.end; ...
    (microsoft.public.vc.language)
  • Re: Memory allocation for an initialized character pointer;
    ... But, speaking strictly in regard to the standard, we can say it is ... Where does the Standard explicitly say that void mainis ... a strictly conforming program can't rely on the order of bit- ... In C89, it's incorrect. ...
    (comp.lang.c)
  • Re: lvalue rvalue discussion
    ... I'm sorry, that's incorrect. ... 'void' is one of the fundamental types in C++, ... Vladimir Grigoriev: ... Constructors are declared sans result type, not even void. ...
    (microsoft.public.vc.language)