Thread: is this the same thing.

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    is this the same thing.

    when i say

    *((&(A[5]))-3).value=7;

    it the same as saying
    *(A+2).value=7
    ??

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think so - but if you find code that does this sort of thing (or similar things), stay away!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    31
    Why don't you write a simple program to check just that?

    Code:
    if ((&(A[5]))-3) == (A+2)) {
      printf ("same addr!\n");
    } else {
      printf ("doh!\n");
    }
    (Just for the record: Yes they will point to the same addr)

    Edit: I are the slowpoke!
    Last edited by edoceo; 03-19-2009 at 02:19 PM. Reason: slow slow slow

  4. #4
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but you said that i cant use & expression on the left side

    only on the right

    you said its rvalue
    ??

  5. #5
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by transgalactic2 View Post
    when i say

    *((&(A[5]))-3).value=7;

    it the same as saying
    *(A+2).value=7
    ??
    yep! although obfuscated

  6. #6
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    when i did
    &t=&x

    you said it wrong

    but *((&(A[5]))-3).value=7; is ok??

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by transgalactic2 View Post
    but you said that i cant use & expression on the left side

    only on the right

    you said its rvalue
    ??
    You aren't because the leftmost expr. is * not &

  8. #8
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    ahh thanks

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by transgalactic2 View Post
    when i say

    *((&(A[5]))-3).value=7;

    it the same as saying
    *(A+2).value=7
    ??
    Which can be simplified furthur to just:
    Code:
    A[2].value = 7;
    Also, true you can't do &t = ...
    but you already know you can do t = ...
    AND you know that *&t is the same as t
    therefore *&t = ... is fine.
    It is also perfectly fine to go
    Code:
    if (&t == ...)
    because that doesn't involve assignment.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pause/idle thing
    By freedik in forum Windows Programming
    Replies: 13
    Last Post: 08-22-2003, 09:46 AM
  2. A very strange thing
    By gustavosserra in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 12:43 PM
  3. most challenging thing to program
    By volk in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 03-28-2003, 03:56 PM
  4. newbie needs help comprehending simple thing
    By A helpless one in forum C++ Programming
    Replies: 6
    Last Post: 12-16-2002, 09:23 PM
  5. PingPong But how to make 2 thing at the same time..
    By Gugge in forum C Programming
    Replies: 5
    Last Post: 04-02-2002, 06:13 PM