const and struct pointers

Robert Adsett semicon at watsci.uwaterloo.ca
Sat Feb 24 10:24:14 AEST 1990


  I ran into a problem with my compiler (it claims to be ANSI
compliant) the other day while using the const keyword.  I'd like to
know if whether I've run into a compiler bug or my understanding of
the const keyword is incomplete.  The problem shows up in the code
fragment that follows. 
 
#include <math.h>

struct qwert { int a; double b;};

void asdf( struct qwert a);

const double a = 3.0;

void junk( const double *b, const struct qwert *c)
{

(void)exp(a);    /* Works */
(void)exp(*b);   /* Works */
asdf( *c);       /* Type mismatch ???? */
}

   The compiler gives a type mismatch in argument error for the line
indicated.  If I either add const to the prototype or remove it from
the argument to junk it compiles without error.  Is there some reason
that 'const double *b' should be treated differently from 'const
struct qwert *c'?  Surely it's not possible for a structure that's
passed by value to be changed by the called function?

--
		Robert Adsett  <semicon at watsci.UWaterloo.ca>
		Dept. of Phys, Univ. of Waterloo, Waterloo Ont. Canada



More information about the Comp.lang.c mailing list