assignment suppression in sscanf

Discussion in 'C Programming' started by Bart Vandewoestyne, Apr 27, 2010.

  1. I noticed that the following line

    sscanf(buf, "%*d %lf %lf %*lf", VX+n, VY+n);

    leads to the following gcc warning:

    warning: use of assignment suppression and length modifier
    together in gnu_scanf format

    I would assume this is due to the %*lf format specifier. To
    solve the problem, i noticed that changing the line to

    sscanf(buf, "%*d %lf %lf %*f", VX+n, VY+n);

    makes the warning go away. It appears that %*lf is something
    'bad' to use, but why? Is my solution indeed the best way to get
    rid of this warning and make my code more C89 compliant?

    Thanks,
    Bart

    --
    "Share what you know. Learn what you don't."
     
    Bart Vandewoestyne, Apr 27, 2010
    #1
    1. Advertising

  2. On Tue, 27 Apr 2010, Bart Vandewoestyne wrote:

    > I noticed that the following line
    >
    > sscanf(buf, "%*d %lf %lf %*lf", VX+n, VY+n);
    >
    > leads to the following gcc warning:
    >
    > warning: use of assignment suppression and length modifier
    > together in gnu_scanf format
    >
    > I would assume this is due to the %*lf format specifier. To solve the
    > problem, i noticed that changing the line to
    >
    > sscanf(buf, "%*d %lf %lf %*f", VX+n, VY+n);
    >
    > makes the warning go away. It appears that %*lf is something 'bad' to
    > use, but why? Is my solution indeed the best way to get rid of this
    > warning and make my code more C89 compliant?


    It is not something "bad", but a mild conflict of interest. The conversion
    specifier character "f" tells sscanf() how a matching input sequence must
    look like. The length modifier "l" specifies the size of the receiving
    object (which, in case of "f", specifies range and precision). The "*"
    assignment-suppressing character tells sscanf() to parse (validate) the
    input sequence, but not to try to convert it. Since you don't want to
    store anything, specifying the size of the (nonexistent) receiving object
    is useless.

    gcc warns you to clarify what you want sscanf() to do. I won't try to
    determine whether the standard allows the "%*lf" directive (superficially,
    I think it does), but "%*f" seems better style.

    Cheers,
    lacos
     
    Ersek, Laszlo, Apr 27, 2010
    #2
    1. Advertising

  3. Bart Vandewoestyne

    Eric Sosman Guest

    On 4/27/2010 8:18 AM, Bart Vandewoestyne wrote:
    > I noticed that the following line
    >
    > sscanf(buf, "%*d %lf %lf %*lf", VX+n, VY+n);
    >
    > leads to the following gcc warning:
    >
    > warning: use of assignment suppression and length modifier
    > together in gnu_scanf format
    >
    > I would assume this is due to the %*lf format specifier. To
    > solve the problem, i noticed that changing the line to
    >
    > sscanf(buf, "%*d %lf %lf %*f", VX+n, VY+n);
    >
    > makes the warning go away. It appears that %*lf is something
    > 'bad' to use, but why? Is my solution indeed the best way to get
    > rid of this warning and make my code more C89 compliant?


    The code conforms, either with or without the "l" modifier,
    and does what you want: It matches and converts a floating-point
    number, ignores it, and moves onward (in this case, to the end
    of the format string).

    However, the "l" is largely meaningless. If it were not for
    the "*", the "l" would mean "the corresponding argument is a pointer
    to double, so store the converted value as a double (not as a float
    or as a long double)." Because of the "*", though, there *is* no
    corresponding argument for the "l" to describe, and no point in
    trying to describe it. You've told us you have no sister, and also
    mentioned that she's blonde.

    Presumably, gcc thinks it odd -- not wrong, necessarily, but
    odd -- to specify so much detail about an argument that doesn't
    exist. gcc generates a message to draw your attention to the
    oddity, in case there really is something wrong with it -- maybe
    the "*" should actually have been on a different conversion, for
    example. gcc generates messages for other perfectly legal but
    suspicious constructs like `if (x = y)', in a similar vein.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Apr 27, 2010
    #3
  4. Bart Vandewoestyne <> writes:

    > I noticed that the following line
    >
    > sscanf(buf, "%*d %lf %lf %*lf", VX+n, VY+n);
    >
    > leads to the following gcc warning:
    >
    > warning: use of assignment suppression and length modifier
    > together in gnu_scanf format
    >
    > I would assume this is due to the %*lf format specifier. To
    > solve the problem, i noticed that changing the line to
    >
    > sscanf(buf, "%*d %lf %lf %*f", VX+n, VY+n);
    >
    > makes the warning go away. It appears that %*lf is something
    > 'bad' to use, but why?


    This is not a required diagnostic; gcc is just being helpful. Nothing
    about %*lf is "wrong" in the sense of being a constraint violation or
    invoking undefined behaviour (unless I've missed something, of course).

    I think the reason gcc chooses to tell you this is that the length
    modifier (l in this case) has no effect of what constitutes a valid
    input sequence. As a result, %*f and %*lf mean exactly the same thing
    so there is some merit in telling you that the format string is
    over-specified.

    > Is my solution indeed the best way to get
    > rid of this warning and make my code more C89 compliant?


    I think your code is fine with or without this change but I would remove
    the 'l' simply to clean up the compiler's ouptut.

    --
    Ben.
     
    Ben Bacarisse, Apr 27, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Buroff
    Replies:
    5
    Views:
    5,510
    Alan Moore
    Sep 28, 2004
  2. Replies:
    0
    Views:
    972
  3. coder

    Suppression of URL details

    coder, Dec 11, 2007, in forum: HTML
    Replies:
    27
    Views:
    940
    dorayme
    Dec 20, 2007
  4. , India

    question on assignment suppression in scanf

    , India, Oct 18, 2008, in forum: C Programming
    Replies:
    2
    Views:
    369
    Ben Bacarisse
    Oct 18, 2008
  5. Alf P. Steinbach

    Ann: MSVC sillywarning suppression

    Alf P. Steinbach, Jun 15, 2010, in forum: C++
    Replies:
    2
    Views:
    465
    Alf P. Steinbach
    Jun 15, 2010
Loading...

Share This Page