Thread: Are these expressions = ?

  1. #1
    Registered User
    Join Date
    Apr 2011

    Are these expressions = ?

    (((unsigned long *)(0x483069E0))[0] | 0x00000003)
    (unsigned long *0x483069E0)[0] | 0x00000003.

    Also could someone explain to me the concatenation of the array? I have not seen that syntax before.

    Thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > Are these expressions = ?
    Compile them, run them, find out.

    And no, they're not the same.

    > Also could someone explain to me the concatenation of the array?
    I've no idea what you're talking about. There is no standard way to append one array onto the end of another array.
    The only exception being where you have arrays of char terminated by \0, in which case there is 'strcat'
    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.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Rochester, NY
    The person is making a pointer to a long, then dereferencing it with an offset of 0 ( [0] ), giving you the long at that the pointer points to.

    In the first expression, it appears as though they're taking that magical number, casting it to an unsigned long pointer, then dereferencing it at the head, then bitwise or'ing that with 3.

    In essence, say there's an array of longs which starts at addr 0x483069E0 - ending unknown (or known somewhere else). It takes that address, casts it to an unsigned long pointer (probably to satisfy a compiler), then goes to the value at that address, and bitwise OR's it with 3.
    0x483069E0 --> 0
               --> 0
               --> 0
    0x483069E0 --> 3
               --> 0
               --> 0
    If I'm understanding it correctly, another way of doing the first would be:
    unsigned long* tmpPtr = 0x483069E0;
    *tmpPtr | 3;
    Note: The value isn't saved anywhere, it's non-destructive, this has to go as a function arg or be returned to something or something.

    Which looks much better, but doesn't spend time on the stack, allocating space for the tmpPtr variable, could be important in a time critical environment...but time is typically not THAT important. Even on embedded systems the latter should work without issue.

    The second doesn't appear to be a valid expression. Without parenthesis around the "unsigned long*" or "unsigned long" - it's a type specification, which needs to be followed by a name. Not quite sure what that second one is getting at.
    Last edited by Syndacate; 04-18-2011 at 10:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to solve expressions like this
    By karan in forum C Programming
    Replies: 7
    Last Post: 03-28-2010, 02:28 AM
  2. Expressions
    By DMEngOba in forum C Programming
    Replies: 2
    Last Post: 05-25-2009, 03:56 PM
  3. Logical expressions
    By En-Motion in forum C Programming
    Replies: 7
    Last Post: 10-14-2008, 04:41 PM
  4. Regular expressions
    By jverkoey in forum A Brief History of
    Replies: 9
    Last Post: 01-23-2005, 09:36 PM
  5. expressions
    By lizardking3 in forum Tech Board
    Replies: 5
    Last Post: 02-18-2003, 10:41 AM