Article View: comp.std.c
Article #2950Casting const; Is this standard conforming?
From: Robert Lupton the Good
Date: Mon, 16 Nov 1992 20:08
Date: Mon, 16 Nov 1992 20:08
31 lines
1413 bytes
1413 bytes
I've never used const modifiers, so I assumed that this would be OK,
#include <stdio.h>
int
main()
{
const int i = 0;
(int)i = 1; /* Fails */
*(int *)&i = 1; /* OK */
return(0);
}
Thinking about ROMs my guess is that gcc and the IBM xlc compilers are
correct to reject the former assignment, and that their acceptance of
the latter is permitted, but could anyone comment?
What do you think about the portability of the cast? (I want to set
the variable once in a private place just after mallocing it, in case
you wonder why I am trying to get around a const restriction, and
don't see why I can't just initialise it)
Robert
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Robert Lupton rhl@astro.princeton.edu
(609) 683 8252 (Home) (609) 258 3811 (Work)
Technical Details
Message-ID:
<1992Nov16.200843.5565@Princeton.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!jvnc.net!princeton!grendel!rhlShow Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!jvnc.net!princeton!grendel!rhl From: rhl@grendel.Princeton.EDU (Robert Lupton the Good) Subject: Casting const; Is this standard conforming? Message-ID: <1992Nov16.200843.5565@Princeton.EDU> Originator: news@nimaster Sender: news@Princeton.EDU (USENET News System) Nntp-Posting-Host: grendel.princeton.edu Organization: Princeton University Date: Mon, 16 Nov 1992 20:08:43 GMT Lines: 31