PDA

View Full Version : C code working in Linux but not in Windows



Bernie_82
04-18-2004, 07:50 PM
hey there
i just loaded my C code i have been working on in linux into my home visual 6 studio and i cant get my code to compile
i have set up the linking properly and it finds gl.h and the definition for typedef int GLint;
but it says that 'GLint CirclePoints = 60;'
is an illegal use of this type as an expression
if anyone could help me that would be great

plasmonster
04-18-2004, 08:04 PM
I've never seen the like. Where is that expression located: GLint CirclePoints = 60 ?

plasmonster
04-18-2004, 08:06 PM
I'll bet that your header is not visible from your source file.

Bernie_82
04-18-2004, 08:06 PM
#include <Gl\glut.h>
#include <math.h>
#define PI 3.14159
void display(void)
{
int i = 0;
float angle;
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
GLint CirclePoints = 60;
etc......
if you need more info i can post the whole program..also i am a newbie at openGl so go easy :)

plasmonster
04-18-2004, 08:08 PM
Don't forget this:
#include <GL/gl.h>

Bernie_82
04-18-2004, 08:25 PM
hey there portal
i loaded my code onto a web page because i still cant get it working
have a look at it at www.geocities.com/bernief_1982/index.html (http://www.geocities.com/bernief_1982/index.html)
cheers

plasmonster
04-18-2004, 08:29 PM
If the compiler is complaining about an undefined type, then you know what the problem is: it can't see the header - it's that simple.
GLint, and all the other basic GL types are defined in gl.h.

edit:
try this:
#include <windows.h>
#include <GL\gl.h>
#include <GL\glut.h>

Bernie_82
04-18-2004, 08:39 PM
the compiler is just complaining about an illegal use of the type
it finds the definition in gl.h fine but still doesnt like the code
thats the problem im having

plasmonster
04-18-2004, 08:50 PM
Bernie_82, if there's something wrong with your code, it's not immediately obvious to me what it is. What exactly is the compiler telling you?

Bernie_82
04-18-2004, 08:53 PM
This is exactly what its telling me.
You can see how it finds the declaration of GLint
thats why i find it weird that it wont work

C:\main.c(13) : error C2275: 'GLint' : illegal use of this type as an expression

d:\program files\microsoft visual studio\vc98\include\gl\gl.h(48) : see declaration of 'GLint'

C:\main.c(13) : error C2146: syntax error : missing ';' before identifier 'CirclePoints'

C:\main.c(13) : error C2065: 'CirclePoints' : undeclared identifier

plasmonster
04-18-2004, 08:57 PM
Wow, it's been a long time since I coded in C, so long that I can't remember if you can initialize a variable in a declaration...
Am I crazy?
Try this:
GLint CirclePoints;
CirclePoints = 60;

Bernie_82
04-18-2004, 09:02 PM
yeah i couldnt remember that either so i tried that before...when i do change it the problem is the same in the sense that it says illegal use of GLint as an expression
this code is right in the sense that on my universities linux machines it has no trouble compiling
im just trying to get it to work at home so i can code in comfort

plasmonster
04-18-2004, 09:10 PM
This is mighty puzzling! Is this a plain vc6 install, right out of the box? Did you include windows.h? Did you try this in c++?

Bernie_82
04-18-2004, 09:11 PM
yeah i did all that
i'll figure it out im sure
probably something stupid along the way
thanx for the help though

Bob
04-19-2004, 12:05 AM
In C, you're not allowed to declare local variables anywhere except at the beginnig of a block (*). All declarations must happen first in a block.

Wrong:

void display(void)
{
int i = 0;
float angle;
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
GLint CirclePoints = 60;Correct:

void display(void)
{
int i = 0;
float angle;
GLint CirclePoints = 60;
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);(*) I don't know what the latest C-spec (C99 I believe) says about this, but I know for sure VC6 does not support it. If it's allowed in C99, then maybe your compiler on Linux supports it and therefore does not complain.

Bernie_82
04-19-2004, 12:15 AM
thanks for that but i figured it out a little while b4
too many things to remember in too many languages nowadays