Are these expressions = ?

This is a discussion on Are these expressions = ? within the C Programming forums, part of the General Programming Boards category; (((unsigned long *)(0x483069E0))[0] | 0x00000003) = (unsigned long *0x483069E0)[0] | 0x00000003. Also could someone explain to me the concatenation of ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

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

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Rochester, NY
    Posts
    196
    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.
    Code:
    0x483069E0 --> 0
               --> 0
               --> 0
    AFTER
    0x483069E0 --> 3
               --> 0
               --> 0
    If I'm understanding it correctly, another way of doing the first would be:
    Code:
    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 11: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, 03:28 AM
  2. Expressions
    By DMEngOba in forum C Programming
    Replies: 2
    Last Post: 05-25-2009, 04:56 PM
  3. Logical expressions
    By En-Motion in forum C Programming
    Replies: 7
    Last Post: 10-14-2008, 05:41 PM
  4. Regular expressions
    By jverkoey in forum A Brief History of Cprogramming.com
    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

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