468,491 Members | 2,072 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

FD_SET compiler warning, why that particular warniing?

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
Dec 21 '07 #1
11 3839
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);

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?
Dec 21 '07 #2
In article <fk**********@naig.caltech.edu>,
David Mathog <ma****@caltech.eduwrote:
>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.
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)
Dec 21 '07 #3
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <fk**********@naig.caltech.edu>,
David Mathog <ma****@caltech.eduwrote:
>>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.

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
Dec 21 '07 #4
ja*********@verizon.net wrote:
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);

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
Dec 21 '07 #5
David Mathog <ma****@caltech.eduwrites:
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) <ks***@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"
Dec 21 '07 #6
David Mathog wrote:
ja*********@verizon.net wrote:
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);

When compiled with

gcc -Wall -pedantic -stc=c99
That should be std, not stc, right?
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 ')'.
Dec 21 '07 #7
On Fri, 21 Dec 2007 12:40:55 -0800, Ben Pfaff <bl*@cs.stanford.edu>
wrote in comp.lang.c:
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <fk**********@naig.caltech.edu>,
David Mathog <ma****@caltech.eduwrote:
>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.
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
Dec 22 '07 #8
Jack Klein <ja*******@spamcop.netwrites:
On Fri, 21 Dec 2007 12:40:55 -0800, Ben Pfaff <bl*@cs.stanford.edu>
wrote in comp.lang.c:
[...]
>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) <ks***@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"
Dec 22 '07 #9
On Fri, 21 Dec 2007 19:01:40 -0800, Keith Thompson <ks***@mib.org>
wrote in comp.lang.c:
Jack Klein <ja*******@spamcop.netwrites:
On Fri, 21 Dec 2007 12:40:55 -0800, Ben Pfaff <bl*@cs.stanford.edu>
wrote in comp.lang.c:
[...]
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
Dec 23 '07 #10
Jack Klein <ja*******@spamcop.netwrites:
On Fri, 21 Dec 2007 19:01:40 -0800, Keith Thompson <ks***@mib.org>
wrote in comp.lang.c:
>Jack Klein <ja*******@spamcop.netwrites:
[...]
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) <ks***@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"
Dec 23 '07 #11
ja*********@verizon.net wrote:
David Mathog wrote:
ja*********@verizon.net wrote:
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);
>it issued this warning for that line number:
>>
> error: 'FD_SET' undeclared (first use in this function)
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
Dec 24 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by thule | last post: by
5 posts views Thread by Robert A Riedel | last post: by
1 post views Thread by John Harris | last post: by
4 posts views Thread by silversurfer2025 | last post: by
11 posts views Thread by zeppe | last post: by
29 posts views Thread by Bob | last post: by
9 posts views Thread by bacbacdinner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.