Mail Archives: djgpp/1995/04/18/12:21:37
X-Sender: dpmurach AT students DOT wisc DOT edu
From: dpmurach AT students DOT wisc DOT edu (Daniel Murach)
The test programs that came with the grx library compile fine.
However, when I rearranged the programs I had problems. I tried to
make one .c file to set the mode and draw the pictures, but when I try
to compile I get an error. What is wrong with my code?
this file:
#include <grx.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
GrSetMode(GR_default_graphics);
Here is your problem, "C" requires that all variable declarations preceed code
in a block. You will have to set x, y, ww, & wh after calling GrSetMode and
*MUST* call GrSetMode *AFTER* declaring these. See below....
int x = GrSizeX();
int y = GrSizeY();
int ww = (x / 2) - 10;
int wh = (y / 2) - 10;
int c;
GrContext *w1 = GrCreateSubContext(5,5,ww+4,wh+4,NULL,NULL);
}
gives me a error along the lines of "parse error before 'int' ..."
What am I missing?
eternally thankful for all the patience...
Daniel.
So the code should be:
#include <grx.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
int x;
int y;
int ww;
int wh;
int c;
GrSetMode(GR_default_graphics);
x = GrSizeX();
y = GrSizeY();
ww = (x / 2) - 10;
wh = (y / 2) - 10;
GrContext *w1 = GrCreateSubContext(5,5,ww+4,wh+4,NULL,NULL);
}
Or maybe even:
#include <grx.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
GrSetMode(GR_default_graphics);
/* This new block lets you declare these after the above.
However, their scope is only the block. */
{
int x = GrSizeX();
int y = GrSizeY();
int ww = (x / 2) - 10;
int wh = (y / 2) - 10;
int c;
GrContext *w1 = GrCreateSubContext(5,5,ww+4,wh+4,NULL,NULL);
}
}
--
Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com
- Raw text -