Connecting Tech Pros Worldwide Forums | Help | Site Map

FD_SET compiler warning, why that particular warniing?

David Mathog
Guest
 
Posts: n/a
#1: Dec 21 '07
There was an editing error in one of my programs giving this line (two
left parentheses, one right):

FD_SET((ncmd->cmd_in_fd,&read_set);

When compiled with

gcc -Wall -pedantic -stc=c99

it issued this warning for that line number:

error: 'FD_SET' undeclared (first use in this function)

There's no argument that the line of code was wrong. I am curious
though why a compiler would choose to emit that particular message.
It was most confusing since FD_SET calls preceded and followed this one,
and they were not generating these "undeclared" warnings.

Regards,

David Mathog

jameskuyper@verizon.net
Guest
 
Posts: n/a
#2: Dec 21 '07

re: FD_SET compiler warning, why that particular warniing?


David Mathog wrote:
Quote:
There was an editing error in one of my programs giving this line (two
left parentheses, one right):
>
FD_SET((ncmd->cmd_in_fd,&read_set);
>
When compiled with
>
gcc -Wall -pedantic -stc=c99
>
it issued this warning for that line number:
>
error: 'FD_SET' undeclared (first use in this function)
>
There's no argument that the line of code was wrong. I am curious
though why a compiler would choose to emit that particular message.
It was most confusing since FD_SET calls preceded and followed this one,
and they were not generating these "undeclared" warnings.
How is FD_SET defined?
Walter Roberson
Guest
 
Posts: n/a
#3: Dec 21 '07

re: FD_SET compiler warning, why that particular warniing?


In article <fkh2et$4jo$1@naig.caltech.edu>,
David Mathog <mathog@caltech.eduwrote:
Quote:
>There was an editing error in one of my programs giving this line (two
>left parentheses, one right):
Quote:
FD_SET((ncmd->cmd_in_fd,&read_set);
Quote:
>When compiled with
Quote:
gcc -Wall -pedantic -stc=c99
Quote:
>it issued this warning for that line number:
Quote:
error: 'FD_SET' undeclared (first use in this function)
Quote:
>There's no argument that the line of code was wrong. I am curious
>though why a compiler would choose to emit that particular message.
>It was most confusing since FD_SET calls preceded and followed this one,
>and they were not generating these "undeclared" warnings.
Suppose FD_SET is an object-like macro, then because of the missing
bracket, the line is not an object-like invocation of the macro
and so FD_SET would not be recognized as a macro name on that line.
--
So you found your solution
What will be your last contribution?
-- Supertramp (Fool's Overture)
Ben Pfaff
Guest
 
Posts: n/a
#4: Dec 21 '07

re: FD_SET compiler warning, why that particular warniing?


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
Quote:
In article <fkh2et$4jo$1@naig.caltech.edu>,
David Mathog <mathog@caltech.eduwrote:
Quote:
>>There was an editing error in one of my programs giving this line (two
>>left parentheses, one right):
>
Quote:
> FD_SET((ncmd->cmd_in_fd,&read_set);
>
Quote:
>>When compiled with
>
Quote:
> gcc -Wall -pedantic -stc=c99
>
Quote:
>>it issued this warning for that line number:
>
Quote:
> error: 'FD_SET' undeclared (first use in this function)
>
Quote:
>>There's no argument that the line of code was wrong. I am curious
>>though why a compiler would choose to emit that particular message.
>>It was most confusing since FD_SET calls preceded and followed this one,
>>and they were not generating these "undeclared" warnings.
>
Suppose FD_SET is an object-like macro, then because of the missing
bracket, the line is not an object-like invocation of the macro
and so FD_SET would not be recognized as a macro name on that line.
That doesn't make sense. To be expanded, an object-like macro
doesn't need to be followed by any particular token. And if you
actually meant function-like macro, then the preprocessor would
continue reading the arguments from succeeding lines of the
source file; the lack of a right parenthesis on the same line
would not dissuade it from the idea that it was expanding a
macro.
--
"In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt." -- Blair P. Houghton
David Mathog
Guest
 
Posts: n/a
#5: Dec 21 '07

re: FD_SET compiler warning, why that particular warniing?


jameskuyper@verizon.net wrote:
Quote:
David Mathog wrote:
Quote:
>There was an editing error in one of my programs giving this line (two
>left parentheses, one right):
>>
> FD_SET((ncmd->cmd_in_fd,&read_set);
>>
>When compiled with
>>
> gcc -Wall -pedantic -stc=c99
>>
>it issued this warning for that line number:
>>
> error: 'FD_SET' undeclared (first use in this function)
>>
>There's no argument that the line of code was wrong. I am curious
>though why a compiler would choose to emit that particular message.
>It was most confusing since FD_SET calls preceded and followed this one,
>and they were not generating these "undeclared" warnings.
>
How is FD_SET defined?
Good question. I believe these are the ones it is using:

#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)

and

#define __FD_SET(fd,fdsetp) \
__asm__ __volatile__("btsl %1,%0": \
"=m" (*(__kernel_fd_set *) (fdsetp)):"r" ((int) (fd)))

I had to take a little white space out of the latter one to keep
it from wrapping.

Regards,

David Mathog
Keith Thompson
Guest
 
Posts: n/a
#6: Dec 21 '07

re: FD_SET compiler warning, why that particular warniing?


David Mathog <mathog@caltech.eduwrites:
Quote:
There was an editing error in one of my programs giving this line (two
left parentheses, one right):
>
FD_SET((ncmd->cmd_in_fd,&read_set);
>
When compiled with
>
gcc -Wall -pedantic -stc=c99
>
it issued this warning for that line number:
>
error: 'FD_SET' undeclared (first use in this function)
>
There's no argument that the line of code was wrong. I am curious
though why a compiler would choose to emit that particular message.
It was most confusing since FD_SET calls preceded and followed this one,
and they were not generating these "undeclared" warnings.
FD_SET is not part of standard C, but it's defined as a function-like
macro on many systems. Assuming it's defined that way on your system,
the only thing the C standard says is that implementation must produce
at least one diagnostic. The standard doesn't require the diagnostic
to make sense.

Detailed questions about gcc's behavior would be better asked on
gnu.gcc.help. But here's a hint: The output of "gcc -E" is
instructive. (And it's odd that gcc continues processing after a
fatal preprocessing error; that's why gcc gets confused.)

If we want to discuss this in the context of standard C (without
dependence either on gcc or on headers that define FD_SET), here's a
standalone invalid program that illustrates the same issue:

void fd_set(int x, int y) { }
#define FD_SET(x, y) fd_set(x, y)
void foo(void)
{
int x = 0, y = 0;
FD_SET((x, y); /* Note extra left parenthesis. */
}

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
jameskuyper@verizon.net
Guest
 
Posts: n/a
#7: Dec 21 '07

re: FD_SET compiler warning, why that particular warniing?


David Mathog wrote:
Quote:
jameskuyper@verizon.net wrote:
Quote:
David Mathog wrote:
Quote:
There was an editing error in one of my programs giving this line (two
left parentheses, one right):
>
FD_SET((ncmd->cmd_in_fd,&read_set);
>
When compiled with
>
gcc -Wall -pedantic -stc=c99
That should be std, not stc, right?
Quote:
Quote:
Quote:
it issued this warning for that line number:
>
error: 'FD_SET' undeclared (first use in this function)
>
There's no argument that the line of code was wrong. I am curious
though why a compiler would choose to emit that particular message.
It was most confusing since FD_SET calls preceded and followed this one,
and they were not generating these "undeclared" warnings.
How is FD_SET defined?
>
Good question. I believe these are the ones it is using:
>
#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
Using your defective code and those #defines, I get:

unterminated argument list invoking macro "FD_SET"

which makes perfect sense, unlike the message you've been getting. Is
it possible that there's a ')' somewhere else in your code matching
the first '(' in your use of FD_SET? If so, then the macro won't fail,
giving you all kinds of opportunities for the program itself to fail
after the macro is expanded. How weird the error messages are that you
would get depends upon how much of the rest of your program lies
between the first '(' and the matching ')'.
Jack Klein
Guest
 
Posts: n/a
#8: Dec 22 '07

re: FD_SET compiler warning, why that particular warniing?


On Fri, 21 Dec 2007 12:40:55 -0800, Ben Pfaff <blp@cs.stanford.edu>
wrote in comp.lang.c:
Quote:
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>
Quote:
In article <fkh2et$4jo$1@naig.caltech.edu>,
David Mathog <mathog@caltech.eduwrote:
Quote:
>There was an editing error in one of my programs giving this line (two
>left parentheses, one right):
Quote:
FD_SET((ncmd->cmd_in_fd,&read_set);
Quote:
>When compiled with
Quote:
gcc -Wall -pedantic -stc=c99
Quote:
>it issued this warning for that line number:
Quote:
error: 'FD_SET' undeclared (first use in this function)
Quote:
>There's no argument that the line of code was wrong. I am curious
>though why a compiler would choose to emit that particular message.
>It was most confusing since FD_SET calls preceded and followed this one,
>and they were not generating these "undeclared" warnings.
Suppose FD_SET is an object-like macro, then because of the missing
bracket, the line is not an object-like invocation of the macro
and so FD_SET would not be recognized as a macro name on that line.
>
That doesn't make sense. To be expanded, an object-like macro
doesn't need to be followed by any particular token. And if you
actually meant function-like macro, then the preprocessor would
continue reading the arguments from succeeding lines of the
source file; the lack of a right parenthesis on the same line
would not dissuade it from the idea that it was expanding a
macro.
Has someone forgotten that macros end at the first unescaped newline?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Keith Thompson
Guest
 
Posts: n/a
#9: Dec 22 '07

re: FD_SET compiler warning, why that particular warniing?


Jack Klein <jackklein@spamcop.netwrites:
Quote:
On Fri, 21 Dec 2007 12:40:55 -0800, Ben Pfaff <blp@cs.stanford.edu>
wrote in comp.lang.c:
[...]
Quote:
Quote:
>That doesn't make sense. To be expanded, an object-like macro
>doesn't need to be followed by any particular token. And if you
>actually meant function-like macro, then the preprocessor would
>continue reading the arguments from succeeding lines of the
>source file; the lack of a right parenthesis on the same line
>would not dissuade it from the idea that it was expanding a
>macro.
>
Has someone forgotten that macros end at the first unescaped newline?
Macro definitions do. Macro invocations (for function-like macros) do
not. For example, if FD_SET is a macro that expects two arguments,
then this:

FD_SET (
arg1,
arg2
)

is valid.

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jack Klein
Guest
 
Posts: n/a
#10: Dec 23 '07

re: FD_SET compiler warning, why that particular warniing?


On Fri, 21 Dec 2007 19:01:40 -0800, Keith Thompson <kst-u@mib.org>
wrote in comp.lang.c:
Quote:
Jack Klein <jackklein@spamcop.netwrites:
Quote:
On Fri, 21 Dec 2007 12:40:55 -0800, Ben Pfaff <blp@cs.stanford.edu>
wrote in comp.lang.c:
[...]
Quote:
Quote:
That doesn't make sense. To be expanded, an object-like macro
doesn't need to be followed by any particular token. And if you
actually meant function-like macro, then the preprocessor would
continue reading the arguments from succeeding lines of the
source file; the lack of a right parenthesis on the same line
would not dissuade it from the idea that it was expanding a
macro.
Has someone forgotten that macros end at the first unescaped newline?
>
Macro definitions do. Macro invocations (for function-like macros) do
not. For example, if FD_SET is a macro that expects two arguments,
then this:
>
FD_SET (
arg1,
arg2
)
>
is valid.
You're absolutely right, and you and this topic have caused me to
learn something new today. That doesn't often happen to me regarding
the C standard these days, so thanks.

Imagine...

"Within the sequence of preprocessing tokens making up an invocation
of a function-like macro, new-line is considered a normal white-space
character."

I never would have guessed.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Keith Thompson
Guest
 
Posts: n/a
#11: Dec 23 '07

re: FD_SET compiler warning, why that particular warniing?


Jack Klein <jackklein@spamcop.netwrites:
Quote:
On Fri, 21 Dec 2007 19:01:40 -0800, Keith Thompson <kst-u@mib.org>
wrote in comp.lang.c:
Quote:
>Jack Klein <jackklein@spamcop.netwrites:
[...]
Quote:
Quote:
Quote:
Has someone forgotten that macros end at the first unescaped newline?
>>
>Macro definitions do. Macro invocations (for function-like macros) do
>not. For example, if FD_SET is a macro that expects two arguments,
>then this:
>>
> FD_SET (
> arg1,
> arg2
> )
>>
>is valid.
>
You're absolutely right, and you and this topic have caused me to
learn something new today. That doesn't often happen to me regarding
the C standard these days, so thanks.
>
Imagine...
>
"Within the sequence of preprocessing tokens making up an invocation
of a function-like macro, new-line is considered a normal white-space
character."
>
I never would have guessed.
The key thing to remember is that an invocation of a function-like
macro is supposed to work just like an ordinary function call.
Standard library functions can additionally be defined as macros.
That wouldn't work if there were syntactic restrictions on macro
invocations beyond those imposed on function calls. (If you happen to
write all your function calls on a single line, you won't run into
this, but there's no requirement to do so.)

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Richard Bos
Guest
 
Posts: n/a
#12: Dec 24 '07

re: FD_SET compiler warning, why that particular warniing?


jameskuyper@verizon.net wrote:
Quote:
David Mathog wrote:
Quote:
jameskuyper@verizon.net wrote:
Quote:
David Mathog wrote:
>There was an editing error in one of my programs giving this line (two
>left parentheses, one right):
>>
> FD_SET((ncmd->cmd_in_fd,&read_set);
Quote:
Quote:
Quote:
>it issued this warning for that line number:
>>
> error: 'FD_SET' undeclared (first use in this function)
Quote:
Quote:
Quote:
How is FD_SET defined?
Good question. I believe these are the ones it is using:

#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
>
Using your defective code and those #defines, I get:
>
unterminated argument list invoking macro "FD_SET"
>
which makes perfect sense, unlike the message you've been getting.
At a guess, the extra open paren makes the compiler think that this is
an invocation of FD_SET(one_argument) with the parenthesised comma
expression (ncmd->cmd_in_fd, &read_set). Since there is no definition
for FD_SET with one argument, only for FD_SET with two arguments, it
complains that it cannot find it. Since it's now thoroughly confused, it
misses the extra syntax error of having a function macro call without
the closing paren.
Yes, it's a broken message. But I'd not be surprised if that's what
happened.

Richard
Closed Thread