472,800 Members | 3,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,800 software developers and data experts.

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 4119
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: thule | last post by:
Okay, thanks to John (THANK YOU SO MUCH). I switched all my header files over to using the new Standard <iostream> and included the using namespace std; . This seems to have fixed all the errors I...
5
by: Robert A Riedel | last post by:
I have a class that is intended to be exported in a DLL that uses another class that is in a static library. All clients that use the DLL will also link with the same static library. In summary,...
5
by: Alan Cobb | last post by:
Hi, In the managed C++ class below I get compile warning C4677 from VS2003. "signature of non-private function contains assembly private type", even though the managed enum is public. I have...
1
by: John Harris | last post by:
We have some C++ code that has a makefile which contains both /W2 and /W3. Due to the way the makefiles are written to be shared across multiple projects, it's not trival to eliminate the duplicate...
6
by: chrisb | last post by:
Hi, Does anyone know if it's possible to generate a custom compiler warning in vs2005? Something like the //todo: comments (possibly //warning: ), but it would show up in the warnings on every...
4
by: silversurfer2025 | last post by:
Hello everyone, I am using a struct inside another class, which can be used through an empty constructor or another one. The definition looks like this: struct Entry{ int index; //line 38...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
29
by: Bob | last post by:
Hi, I have been trying to use some inventive alternative idioms for infinite loops in my code, rather than the same old for(;;) and while(1) - this could be a nice amusing Easter-egg for any...
9
by: bacbacdinner | last post by:
Can anyone explain to me why the code below generates a warning? ///////////////////////////////////////////////////////////// typedef struct testStruct * TestStructRef; typedef TestStructRef * ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.