Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > assignment suppression in sscanf

Reply
Thread Tools

assignment suppression in sscanf

 
 
Bart Vandewoestyne
Guest
Posts: n/a
 
      04-27-2010
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."
 
Reply With Quote
 
 
 
 
Ersek, Laszlo
Guest
Posts: n/a
 
      04-27-2010
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
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      04-27-2010
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
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      04-27-2010
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question on assignment suppression in scanf subramanian100in@yahoo.com, India C Programming 2 10-18-2008 10:58 PM
10 X and noise suppression les Digital Photography 7 03-24-2005 02:22 PM
ava 1.5 - generics "unchecked cast" suppression Steven Buroff Java 5 09-28-2004 01:48 AM
Traffic suppression feature Simon Thibaudeau Cisco 0 04-19-2004 03:38 PM
Does G.711 have silence suppression? Alex VOIP 3 09-05-2003 03:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57