Thread: I need help urgently compiling a c program

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    1

    I need help urgently compiling a c program

    hello I am trying to compile a c program for sudoku. I have declare const instances as global variables, but when i try to compile the code it says that my declarations are not constant, here is some of the code. please help, thank you.

    #include <stdio.h>
    #include <assert.h>


    const int GRIDSIZE = 3;
    const int GRID_SQUARED = GRIDSIZE * GRIDSIZE; //this line
    const int ALL_VALUES = (1<<GRID_SQUARED)-1; //and this give //the error


    int board [GRID_SQUARED][GRID_SQUARED];

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I get the very same error, for all three of the last lines of code you have. You'll have to think of another way to do this.

  3. #3
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    They need to be compile time constants which they clearly are not.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You need to write them out like this
    #define GRIDSIZE 3
    #define GRID_SQUARED (GRIDSIZE * GRIDSIZE)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help urgently
    By jstevanus in forum C++ Programming
    Replies: 15
    Last Post: 12-09-2004, 12:30 PM
  2. Need Help Urgently
    By chener in forum C Programming
    Replies: 3
    Last Post: 06-26-2002, 05:21 PM
  3. need help please urgently
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 12-12-2001, 08:32 AM
  4. need help urgently
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-11-2001, 06:49 AM

Tags for this Thread