old style assignment

This is a discussion on old style assignment within the C Programming forums, part of the General Programming Boards category; I was indenting some code with a program called indent. I accidently indented one of my own codes I wrote, ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    old style assignment

    I was indenting some code with a program called indent. I accidently indented one of my own codes I wrote, but it gave me this warning.
    Code:
    indent: test.c:8: Warning:old style assignment ambiguity in "=-".  Assuming "= -"
    the code was
    Code:
    GLint mov=-8;
    What is ambiguous?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    without seeing the actual code line it would be hard to see why. I would venture to guess it wants a space between = and - to avoide confusion between -=1 and =-1 (example).

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    that is what I though. I just thought that it wouldn't really be confused with -=.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    well lint is pretty anal retentive

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I think =- used to be the same as -=, so with under the old style
    mov=-8; could mean either:

    mov = -8;
    Or:
    mov = mov - 8;

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >What is ambiguous?
    Wow, that's an old warning. Back in the dark ages when the compound assignment operator was added to C, it began with the = and ended with the operation being performed, =- instead of -=, etc... But this caused plenty of confusion because many programmers feared spacing between operators and expected (for some odd reason) things such as v=*p; and x=-y to assign the value pointed to by p to the varible v and the negated value of y to be assigned to x, respectively. The former would try to multiply v by p and the latter would subtract y from x. In light of the surprises, the compound assignment operators were reversed to begin with the operation and end with the = so that these styles wouldn't break the meaning of the code.

    But this was some time ago, and I don't know of any compiler today that could possibly parse move=-8 incorrectly.
    My best code is written with the delete key.

  7. #7
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    It wasn't a compiler, it was a program that automatically indents:
    http://www.gnu.org/software/indent/indent.html
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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