daveh@marob.MASA.COM (Dave Hammond) (01/31/89)
Ok, I've racked my brain long enough on this one. System is a vanilla 386 running SCO Xenix 2.3 -- when compiling with the standard warning level (-W 1) I get no warnings at all; when I switch to the next higher warning level (-W 2) the following completely unobvious warning appears: ../include/dsipriv.h(88) : warning 74: non standard extension used - 'macro formals in strings' (I inserted the newline after "warning 74:" for readability) The macro in question is defined as follows: /* copy IN to OUT for LEN chars, enclosing OUT in dbl. quotes */ #define REQUOTE(in, out, len) if ((in) && (out)) { \ *(out) = '"'; \ Line 88 ---------------------> strncpy((out)+1, (in), (len)); \ (out)[(len)-1] = 0; \ strcat((out), "\""); \ (in) = (out); } Note that this is a warning, not an error. The program compiles fine and the macro does as intended. If any kind soul can clue me as to the problem in the above macro, I'd be for(;;) indebted. -- Dave Hammond ...!uunet!masa.com!{dsix2,marob}!daveh
diamond@csl.sony.JUNET (Norman Diamond) (02/01/89)
In article <490@marob.MASA.COM>, daveh@marob.MASA.COM (Dave Hammond) writes: > ../include/dsipriv.h(88) : warning 74: > non standard extension used - 'macro formals in strings' > /* copy IN to OUT for LEN chars, enclosing OUT in dbl. quotes */ > #define REQUOTE(in, out, len) if ((in) && (out)) { \ > *(out) = '"'; \ > Line 88 ---------------------> strncpy((out)+1, (in), (len)); \ > (out)[(len)-1] = 0; \ > strcat((out), "\""); \ > (in) = (out); } > Note that this is a warning, not an error. The program compiles fine > and the macro does as intended. If any kind soul can clue me as to the > problem in the above macro, I'd be for(;;) indebted. 1. One possible guess (slim chance) is the combination of all three: (a) In one of your invocations, you have a "string literal" for in; (b) Your compiler implements strncpy as a macro; and (c) Your compiler overzealously checks the wrong conditions for issuing that warning. 2. I am really curious about line 91. When you wrap an lvalue in parentheses, doesn't it become an rvalue? How can you assign to it? -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-inventing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?
jeff@unh.UUCP (Jeffrey E. F. Friedl) (02/01/89)
In article <490@marob.MASA.COM>, daveh@marob.MASA.COM (Dave Hammond) writes: about this strict warning from his compiler: > ../include/dsipriv.h(88) : warning 74: > non standard extension used - 'macro formals in strings' > > The macro in question is defined as follows: > > /* copy IN to OUT for LEN chars, enclosing OUT in dbl. quotes */ > #define REQUOTE(in, out, len) if ((in) && (out)) { \ > *(out) = '"'; \ > Line 88 -------------------> strncpy((out)+1, (in), (len)); \ > (out)[(len)-1] = 0; \ > strcat((out), "\""); \ > (in) = (out); } > > [it works fine, but why the warning?] Looks to me as if your preprocessor is not very smart about quotes. Perhaps it thinks that the double quote in line 87 is the beginning of a string (which it would then match with quote #1 in line 90). It thinks it's the same situation as if you had something like #define parenthesize_string_literal(WORD) "(WORD)" or some such thing. Gee, when a preprocessor doesn't know the difference between " and '"'... Since you asked about the warning, I won't offer my comments about the macro itself, although I'd love to.... [(-:]. *jeff* ------------------------------------------------------------------------------ Jeffrey Eric Francis Friedl Box 2173 Babcock House ..!{uunet,decvax}!unh!jeff Durham New Hampshire 03824 So, Steve, how's that '89 Mustang GT Convertible doin'?
teittinen@cc.helsinki.fi (02/02/89)
In article <490@marob.MASA.COM>, daveh@marob.MASA.COM (Dave Hammond) writes: > when > I switch to the next higher warning level (-W 2) the following completely > unobvious warning appears: > > .../include/dsipriv.h(88) : warning 74: > non standard extension used - 'macro formals in strings' > > The macro in question is defined as follows: > > /* copy IN to OUT for LEN chars, enclosing OUT in dbl. quotes */ > #define REQUOTE(in, out, len) if ((in) && (out)) { \ > *(out) = '"'; \ This is wrong ---------------------------^^^ > Line 88 ---------------------> strncpy((out)+1, (in), (len)); \ > (out)[(len)-1] = 0; \ > strcat((out), "\""); \ > (in) = (out); } You may not use quote character (") in character variable. The part I've marked should be '\"' and then you should not get any warnings. -----------------------------------+------------------------------------------- EARN: teittinen@finuh I "Studying is the only way to do nothing Internet: teittinen@cc.helsinki.fi I without anyone complaining about it." -----------------------------------+------------------------------------------- Marko Teittinen, student of computer science -------------------------------------------------------------------------------
wietse@wzv.UUCP (Wietse Z. Venema) (02/03/89)
In article <490@marob.MASA.COM> daveh@marob.masa.com (Dave Hammond) writes:
../include/dsipriv.h(88) : warning 74:
non standard extension used - 'macro formals in strings'
(I inserted the newline after "warning 74:" for readability)
The macro in question is defined as follows:
/* copy IN to OUT for LEN chars, enclosing OUT in dbl. quotes */
#define REQUOTE(in, out, len) if ((in) && (out)) { \
*(out) = '"'; \
Line 88 ---------------------> strncpy((out)+1, (in), (len)); \
(out)[(len)-1] = 0; \
strcat((out), "\""); \
(in) = (out); }
My bet is that the preprocessor thinks that the (out) and (in) occur in
between the " quotes on lines 87 and 90.
--
work: wswietse@eutrc3.uucp | Eindhoven University of Technology
work: wswietse@heitue5.bitnet | Mathematics and Computing Science
home: wietse@wzv.uucp | 5600 MB Eindhoven, The Netherlands
breck@aimt.UU.NET (Robert Breckinridge Beatie) (02/04/89)
In article <10033@diamond.csl.sony.JUNET>, diamond@csl.sony.JUNET (Norman Diamond) writes: > In article <490@marob.MASA.COM>, daveh@marob.MASA.COM (Dave Hammond) writes: > > Line 88 ---------------------> strncpy((out)+1, (in), (len)); \ > > (out)[(len)-1] = 0; \ > > strcat((out), "\""); \ > > (in) = (out); } > > 2. I am really curious about line 91. When you wrap an lvalue in > parentheses, doesn't it become an rvalue? How can you assign to it? Since when? If this is the case, then it seems to be in direct contradiction with K&R (Appendix A Section 7.1) which says: ... The presence of parentheses does not affect whether the expression is an lvalue. And for that matter it even seems to contradict my (somewhat out of date) copy of the dpANS (Oct. 1986) which says (Section 3.3.1): A parenthesized expression is a primary expression. Its type and value are identical to those of the unadorned expression. it is an lvalue if the unadorned expression is an lvalue, ... -- Breck Beatie (408)748-8649 {uunet,ames!coherent}!aimt!breck OR breck@aimt.uu.net "Sloppy as hell Little Father. You've embarassed me no end."
bph@buengc.BU.EDU (Blair P. Houghton) (02/05/89)
In article <1709@cc.helsinki.fi> teittinen@cc.helsinki.fi writes: >In article <490@marob.MASA.COM>, daveh@marob.MASA.COM (Dave Hammond) writes: >> *(out) = '"'; \ >This is wrong ---------------------------^^^ > >You may not use quote character (") in character variable. The part I've >marked should be '\"' and then you should not get any warnings. Not where I come from (i.e., p.181 of K&R, ed. 1). The only time a quote- within-a-quote should give you trouble is when nesting the quotation mark within a quotation of its own ilk: '\'' is the character constant for single-quotation mark; "\"" is the "string pointer" pointing to a double-quotation mark. Note that the converses-- '"' and "'" --require no backslash. --Blair ""'''\"'''" == *("\"'''\\\"'''\"")"
guy@auspex.UUCP (Guy Harris) (02/05/89)
>You may not use quote character (") in character variable. The part I've >marked should be '\"' and then you should not get any warnings. That may well be true, but if so the compiler in question should be fixed - and probably will be fixed, if they intend to make an ANSI C compiler out of it once the standard comes out. The May 13, 1988 dpANS claims in 3.1.3.4 "Character constants" that The double-quote " and question-mark ? are representable either by themselves or by the escape sequences \" and \? respectively.... so within *single* quotes a " by itself should be OK. I tried it on the SunOS 4.0 PCC-derived compiler and it had no problem whatsoever with '"' as a character constant. (You obviously need to escape " inside a *string* constant.)