0

I am trying to implement MATHGL graphs in QT windows. Compilation of the appropriate libraries went fine, and example provided compiles and runs without error.

When trying to build sample code, something strange happens when I try to add a single letter named variable regardless of its type (int, double, others).

This simple code illustrates the problem

#include <mgl2/mgl_cf.h>

int sample(HMGL gr, void *p)
{
  int I; /* REMOVE THIS LINE OR RENAME VARIABLE (TWO LETTERS) FOR COMPILATION  */  

  mgl_rotate(gr,40.,60.,0.);
  mgl_box(gr);

  return 0;
}

int main(int argc,char **argv)
{
  HMGL gr;
  gr = mgl_create_graph_qt(sample,"MathGL examples",0,0);
  return mgl_qt_run();
}

MATHGL version is 2.1.3.1, compiler is gcc 4.7.2, libraries used: -lpng15 -lz -lm -lstdc++ -lmgl -lmgl-qt

Error in compilation reads:

file.c: In function ‘sample’:
file.c:5:7: error: expected identifier or ‘(’ before ‘__extension__’
file.c: In function ‘main’:
file.c:16:6: warning: assignment makes pointer from integer without a cast [enabled by default]

I do not know what I'm missing here, can you please help me??

thanks in advance!!

Khine
  • 23
  • 3
  • 1
    That's a capital "i"? May be a macro that expands to something unexpected. Don't use all-caps variable names. –  Sep 29 '13 at 04:22
  • Yes, indeed that is a capital i. It also has difficulties with capital j and k. Incidentally these are much needed indexes for my program since I work with numerical methods :( – Khine Sep 29 '13 at 04:28
  • again, do **not** use all-caps variable names. [My suspicion: link.](http://www.gnu.org/software/libc/manual/html_node/Complex-Numbers.html) –  Sep 29 '13 at 04:37
  • Anyways, as you pointed out, macro expansion is the most likely scenario, I will try to change indexes. Thank you!! – Khine Sep 29 '13 at 04:38
  • So did you click that link? :) `I` is the imaginary unit. (just so that you know.) –  Sep 29 '13 at 04:39
  • You are welcome! I decided to add this as an answer too. –  Sep 29 '13 at 04:44
  • 1
    Very well!!. What is weird though is that with MATHGL version 2.0.3 there are no errors associated with the use of i,j,k and/or I,J,K. Anyway, is still preferable not to use all-caps variable names as you mentioned earlier. – Khine Sep 29 '13 at 04:51

1 Answers1

0

Your problem: I is most likely a macro for the imaginary unit (as described here).

Use a different variable name (and avoid all-caps variable names in general).