www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/06/24/03:02:02

Date: Fri, 24 Jun 94 02:49:31 EDT
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Problem with 'const'
From: K3A0270 AT EMAIL1 DOT edvz DOT uni-linz DOT ac DOT at (Exler Roland)
Reply-To: K3A0270 AT ALIJKU11 DOT edvz DOT uni-linz DOT ac DOT at

Hi all,

the program appended to this message compiles fine as .cc, but as .c!
I think it's a bug of the c-compiler. (I'm using djgpp 1.11m5)

If anyone can show me a declaration of 'testfunc' where any manipulation
of the pointers or data will be checked by the compiler and without the
obvious (const float**)-cast is Ok with C, please send it to me

Thanks for any suggestions,
  Roland

*********** start of program 'test.c'=='test.cc' ************************
#include<stdio.h>
#include<stdlib.h>
#define collen 10
#define matlen 20

float **mptr;  /* pointer to array of pointer to array of float */

void testfunc(const float *const *const mat)
{ /* just for test, should generate 3 warnings */
  mat++;
  mat[0]++;
  mat[0][0]++;
}

int main(void)
{ int i; int j;
  /* get memory for array of pointer to array of float */
  mptr=(float **) malloc(sizeof(float)*matlen);
  for (i=0; i<matlen; i++)
  { /* get memory for array of float */
    mptr[i]=(float *) malloc(sizeof(float)*collen);
    for (j=0; j<collen; j++)
      mptr[i][j]= i+j;            /* init array with data */
  }
  testfunc(mptr);                 /* ok only with c++ */
  testfunc((const float **)mptr); /* ok! */
  return 0;
}
**************** end of test-program ************************

compile with
  gcc -o test test.c -Wall
  gcc -o test test.cc -Wall


- Raw text -


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