Thread: Help on brookshear machine

  1. #16
    Registered User
    Join Date
    Jun 2005
    Quote Originally Posted by Warzaw View Post
    i used #define but im curious about the enum. do you use it on the array size or the array itself?
    The enum trick (or hack) is used to attach a name to a value, which can be checked by the compiler
    enum {size_reg = 16, size_mem = 256};
    int main()
          int regs[size_reg], mem[size_mem];
            /* whatever */
    This works because an enumeration (even an anonymous enumeration, as in the example) must have all its values known at compile time.

    It is a bit of a dirty trick though, and can be subverted (eg if a variable has the same name as one of the enumeration values).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  2. #17
    Registered User
    Join Date
    Oct 2012
    i see. so its best to use #define for now. though its good to know there is a possible alternative.

    anyway, i was able to get the brookshear program working. thank you guys for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulating a "brookshear machine"
    By kiwisfan in forum C Programming
    Replies: 3
    Last Post: 04-30-2012, 04:55 AM
  2. Convert assembly>machine code, machine code>assembly
    By wenxinleong in forum C Programming
    Replies: 12
    Last Post: 06-23-2011, 10:42 PM
  3. Replies: 4
    Last Post: 01-18-2008, 07:05 PM
  4. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  5. IDEA: A Slot Machine (aka a fruit machine)
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:13 PM