home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3013 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.3 KB  |  44 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!jvnc.net!princeton!grendel!rhl
  3. From: rhl@grendel.Princeton.EDU (Robert Lupton the Good)
  4. Subject: Casting const; Is this standard conforming?
  5. Message-ID: <1992Nov16.200843.5565@Princeton.EDU>
  6. Originator: news@nimaster
  7. Sender: news@Princeton.EDU (USENET News System)
  8. Nntp-Posting-Host: grendel.princeton.edu
  9. Organization: Princeton University
  10. Date: Mon, 16 Nov 1992 20:08:43 GMT
  11. Lines: 31
  12.  
  13. I've never used const modifiers, so I assumed that this would be OK,
  14.  
  15. #include <stdio.h>
  16.  
  17. int
  18. main()
  19. {
  20.    const int i = 0;
  21.    
  22.    (int)i = 1;                /* Fails */
  23.    *(int *)&i = 1;            /* OK */
  24.         
  25.    return(0);
  26. }
  27.            
  28. Thinking about ROMs my guess is that gcc and the IBM xlc compilers are
  29. correct to reject the former assignment, and that their acceptance of
  30. the latter is permitted, but could anyone comment? 
  31.  
  32. What do you think about the portability of the cast? (I want to set
  33. the variable once in a private place just after mallocing it, in case
  34. you wonder why I am trying to get around a const restriction, and
  35. don't see why I can't just initialise it)
  36.  
  37.             Robert
  38.             
  39. -- 
  40.  
  41. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  42. Robert Lupton                                           rhl@astro.princeton.edu
  43. (609) 683 8252 (Home)                    (609) 258 3811 (Work)
  44.