www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/02/16:02:20

Date: Fri, 2 Jun 1995 14:25:26 -0400
From: kagel AT quasar DOT bloomberg DOT com
To: kwasik AT lodz2 DOT p DOT lodz DOT pl
Cc: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Subject: Re: Changing constants...
Reply-To: kagel AT ts1 DOT bloomberg DOT com

   Errors-To: postmaster AT ns1
   Date: Fri, 02 Jun 1995 18:12:55 CET
   From: kwasik AT lodz2 DOT p DOT lodz DOT pl
   Content-Type: text
   Content-Length: 1280


	   Hi !!!

   Yesterday I found something which was rather interesting for me.
   I tried to change constant pointer and the constant value pointed by that
   pointer.
   Well...   When I compiled with bcc everything was OK. Then, I thought
   about gcc from DJGPP package and here's what I've found:

   /* Program const.c */
   int main()
   {
    int var1=13,var2 = 1;
    const int* const swsi = &var1;

    /*There are two errors compiling as C++ !!!*/
    (int *) swsi = &var2;          /*First*/
    (int) *swsi = 2;               /*Second*/
    return 0;
   }

   While compiling as c-source:

   gcc -O -Wall const.c -o const
				     I got two warnings but program compiled
				     just fine.

   while compiling as C++ source:

   gcc -O -Wall -x c++ const.c -o const
				     I got two errors (Yes errors ???) and
				     compilation was stoped.

   Two above constructions are legal !!!. See for example:
   --->"The C++ Programming Language" by Bjarne Stroustrup.<---
       second edition.


   I suppose it's rather strange when C++ compiler finds in a regular statement
   an error. I think it is not as it should be.


						   Balzack.  

It is ILLEGAL and BAD FORM to assign to a CONST ANYTHING!!!!!!!!!!!!!!!!!!!!!!
Bcc is being too lenient and C++ is just stricter than ANSI C.  You got what
you deserved!

-- 
Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com

Variety is the soul of pleasure.  --  Aphra Behn

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019