linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* macros with global variables?
@ 2005-07-14 12:35 Robert P. J. Day
  2005-07-17  8:44 ` Glynn Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Robert P. J. Day @ 2005-07-14 12:35 UTC (permalink / raw)
  To: C programming list

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1310 bytes --]


  not sure if this is outside the scope of this mailing list but i
just downloaded the source for a simple SSL-aware ftp client
(netkit-ftp-ssl), did the configure and the make and got:

ftp.c: In function ârecvrequestâ:
ftp.c:1127: error: âpdataâundeclared (first use in this function)
ftp.c:1127: error: (Each undeclared identifier is reported only once
ftp.c:1127: error: for each function it appears in.)


  ok, fair enough, check the offending header file to find the
following macro definition:

#define is_ssl_fd(X,Y)    ( (SSL_get_fd((X))==0) || \
                            (SSL_get_fd((X))==1) || \
                            (SSL_get_fd((X))==pdata) || \
                            (SSL_get_fd((X))==(Y)) \

  ?????.  so i have a macro which accepts two arguments, but expands
to include an explicit reference to something called "pdata", which
does not exist, hence the error message.

  i tend to avoid defining macros that refer to anything but their own
arguments.  what might the above mean?  is there some well-known idiom
for C programmers that makes the above, in some way, acceptable?
(i've perused the code and the object "pdata", whatever that is, is
simply not defined anywhere.  so is there a context in which the above
makes sense in some way?)

rday

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: macros with global variables?
  2005-07-14 12:35 macros with global variables? Robert P. J. Day
@ 2005-07-17  8:44 ` Glynn Clements
  0 siblings, 0 replies; 2+ messages in thread
From: Glynn Clements @ 2005-07-17  8:44 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: C programming list


Robert P. J. Day wrote:

>   not sure if this is outside the scope of this mailing list but i
> just downloaded the source for a simple SSL-aware ftp client
> (netkit-ftp-ssl), did the configure and the make and got:
> 
> ftp.c: In function ârecvrequestâ:
> ftp.c:1127: error: âpdataâundeclared (first use in this function)
> ftp.c:1127: error: (Each undeclared identifier is reported only once
> ftp.c:1127: error: for each function it appears in.)
> 
>   ok, fair enough, check the offending header file to find the
> following macro definition:
> 
> #define is_ssl_fd(X,Y)    ( (SSL_get_fd((X))==0) || \
>                             (SSL_get_fd((X))==1) || \
>                             (SSL_get_fd((X))==pdata) || \
>                             (SSL_get_fd((X))==(Y)) \
> 
>   ?????.  so i have a macro which accepts two arguments, but expands
> to include an explicit reference to something called "pdata", which
> does not exist, hence the error message.
> 
>   i tend to avoid defining macros that refer to anything but their own
> arguments.  what might the above mean?  is there some well-known idiom
> for C programmers that makes the above, in some way, acceptable?
> (i've perused the code and the object "pdata", whatever that is, is
> simply not defined anywhere.  so is there a context in which the above
> makes sense in some way?)

At the risk of stating the obvious, the only context where it makes
sense is one where "pdata" is defined, as either a global variable,
local variable or macro.

Macros with external references are generally best avoided, although
sometimes it can simplify the code signficantly.

-- 
Glynn Clements <glynn@gclements.plus.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-17  8:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-14 12:35 macros with global variables? Robert P. J. Day
2005-07-17  8:44 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).