Help on brookshear machine

This is a discussion on Help on brookshear machine within the C Programming forums, part of the General Programming Boards category; Originally Posted by Warzaw i used #define but im curious about the enum. do you use it on the array ...

  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 in reply to you, it is likely you deserve it. Suck it up, sunshine, 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.

Page 2 of 2 FirstFirst 12
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, 05:55 AM
  2. Convert assembly>machine code, machine code>assembly
    By wenxinleong in forum C Programming
    Replies: 12
    Last Post: 06-23-2011, 11: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-13-2002, 12:13 AM

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