I need help urgently compiling a c program

This is a discussion on I need help urgently compiling a c program within the C Programming forums, part of the General Programming Boards category; hello I am trying to compile a c program for sudoku. I have declare const instances as global variables, but ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 11:30 AM
  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, 07:32 AM
  4. need help urgently
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-11-2001, 05:49 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21