www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/04/18/12:21:37

Date: Tue, 18 Apr 1995 10:57:00 -0400
From: kagel AT quasar DOT bloomberg DOT com
To: dpmurach AT students DOT wisc DOT edu
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: contexts and such...
Reply-To: kagel AT ts1 DOT bloomberg DOT com

   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 -


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