|
Home > Archive > Unix Programming > May 2007 > What's the purpose of these unused Macros?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
What's the purpose of these unused Macros?
|
|
| K-mart Cashier 2007-05-21, 7:26 pm |
| in the header file
#ifdef LOCK_LOCKF
#ifdef HAVE_SYS_LOCKING_H
#include <sys/lockf.h>
#endif
#ifdef HAVE_SYS_LOCKING_H
#include <sys/file.h>
#endif
#define fseek(file, 0L, 0, lockf(file, 1, 0L)
#define fseek(file, 0L, 0, lockf(file, 0, 0L)
#endif /* LOCK_LOCKF */
#ifdef LOCK_NONE
#define LOCK(file)
#define UNLOCK(FILE)
#endif /*LOCK_NONE*/
When I grepped both LOCK_LOCKF and LOCK_NONE, these macros only showed
up in config.h.in, configure.in, and the header file in question.
Why would the author go through the effort of defining these macros he
doesn't use them throughout the rest of the program?
| |
| Eric Sosman 2007-05-22, 1:18 am |
| K-mart Cashier wrote:
> in the header file
> #ifdef LOCK_LOCKF
> #ifdef HAVE_SYS_LOCKING_H
> #include <sys/lockf.h>
> #endif
> #ifdef HAVE_SYS_LOCKING_H
> #include <sys/file.h>
> #endif
> #define fseek(file, 0L, 0, lockf(file, 1, 0L)
> #define fseek(file, 0L, 0, lockf(file, 0, 0L)
> #endif /* LOCK_LOCKF */
>
> #ifdef LOCK_NONE
> #define LOCK(file)
> #define UNLOCK(FILE)
> #endif /*LOCK_NONE*/
>
> When I grepped both LOCK_LOCKF and LOCK_NONE, these macros only showed
> up in config.h.in, configure.in, and the header file in question.
>
> Why would the author go through the effort of defining these macros he
> doesn't use them throughout the rest of the program?
Are you sure you have transcribed the header accurately?
The C Standard requires diagnostics for the code as shown ...
--
Eric Sosman
esosman@acm-dot-org.invalid
| |
| K-mart Cashier 2007-05-22, 1:18 am |
| On May 21, 6:32 pm, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
> K-mart Cashier wrote:
>
>
>
>
> Are you sure you have transcribed the header accurately?
> The C Standard requires diagnostics for the code as shown ...
>
> --
Here is what is copied and pasted from my terminal
#ifdef LOCK_LOCKF
#ifdef HAVE_SYS_FILE_H
#include <sys/lockf.h>
#endif
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#define LOCK(file) fseek(file, 0L, 0), lockf(file, 1, 0L)
#define UNLOCK(file) fseek(file, 0L, 0), lockf(file, 0, 0L)
#endif /* LOCK_LOCKF */
#ifdef LOCK_LOCKING
#ifdef HAVE_SYS_LOCKING_H
#include <sys/locking.h>
#endif
#define LOCK(file) fseek(file, 0L, 0), chk_lock(file, 1)
#define UNLOCK(file) fseek(file, 0L, 0), chk_lock(file, 0)
#endif /* LOCK_LOCKING */
#ifdef LOCK_NONE
#define LOCK(file)
#define UNLOCK(file)
#endif /* LOCK_NONE */
#ifdef SUID
#define CHN_MODE 0644
#define DEP_MODE 0600
#define USR_MODE 0600
Here is what is my directory
[cdalten@localhost party-2.12]$ ls
chantab configure.in INSTALLATION noisetab party.1 partytab
close.c debug_stty.c install-sh opt.c party.c proc.c
config.h.in ignore.c Makefile.in opttab.c party.h users.c
configure input.c makeopt.c output.c partyhlp
[cdalten@localhost party-2.12]$
And here is what I get when I do a grep
[cdalten@localhost party-2.12]$ grep -iR LOCK_LOCKF ~/party-2.12
/home/cdalten/party-2.12/configure.in: [ AC_DEFINE(LOCK_LOCKF)
/home/cdalten/party-2.12/configure:#define LOCK_LOCKF 1
/home/cdalten/party-2.12/party.h:#ifdef LOCK_LOCKF
/home/cdalten/party-2.12/party.h:#endif /* LOCK_LOCKF */
/home/cdalten/party-2.12/config.h.in:#undef LOCK_LOCKF
[cdalten@localhost party-2.12]$ grep -iR LOCK_NONE ~/party-2.12
/home/cdalten/party-2.12/configure.in: AC_DEFINE(LOCK_NONE)
/home/cdalten/party-2.12/configure:#define LOCK_NONE 1
/home/cdalten/party-2.12/party.h:#ifdef LOCK_NONE
/home/cdalten/party-2.12/party.h:#endif /* LOCK_NONE */
/home/cdalten/party-2.12/config.h.in:#undef LOCK_NONE
[cdalten@localhost party-2.12]$
As you can (sort of see), LOCK_LOCKF and LOCK_NONE only appear in the
header file, configure.h.in and configure.in.
I really don't see what purpose using unused macros would serve in
this case.
| |
| Giorgos Keramidas 2007-05-22, 1:18 am |
| On 21 May 2007 18:52:52 -0700, K-mart Cashier <cdalten@gmail.com> wrote:
> On May 21, 6:32 pm, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
>
> Here is what is copied and pasted from my terminal
>
> #ifdef LOCK_LOCKF
> #ifdef HAVE_SYS_FILE_H
> #include <sys/lockf.h>
> #endif
> #ifdef HAVE_SYS_FILE_H
> #include <sys/file.h>
> #endif
> #define LOCK(file) fseek(file, 0L, 0), lockf(file, 1, 0L)
> #define UNLOCK(file) fseek(file, 0L, 0), lockf(file, 0, 0L)
> #endif /* LOCK_LOCKF */
> [...]
> Here is what is my directory
> [cdalten@localhost party-2.12]$ ls
> chantab configure.in INSTALLATION noisetab party.1 partytab
> close.c debug_stty.c install-sh opt.c party.c proc.c
> config.h.in ignore.c Makefile.in opttab.c party.h users.c
> configure input.c makeopt.c output.c partyhlp
> [cdalten@localhost party-2.12]$
>
> And here is what I get when I do a grep
> [cdalten@localhost party-2.12]$ grep -iR LOCK_LOCKF ~/party-2.12
> /home/cdalten/party-2.12/configure.in: [ AC_DEFINE(LOCK_LOCKF)
> /home/cdalten/party-2.12/configure:#define LOCK_LOCKF 1
> /home/cdalten/party-2.12/party.h:#ifdef LOCK_LOCKF
> /home/cdalten/party-2.12/party.h:#endif /* LOCK_LOCKF */
> /home/cdalten/party-2.12/config.h.in:#undef LOCK_LOCKF
>
> [cdalten@localhost party-2.12]$ grep -iR LOCK_NONE ~/party-2.12
> /home/cdalten/party-2.12/configure.in: AC_DEFINE(LOCK_NONE)
> /home/cdalten/party-2.12/configure:#define LOCK_NONE 1
> /home/cdalten/party-2.12/party.h:#ifdef LOCK_NONE
> /home/cdalten/party-2.12/party.h:#endif /* LOCK_NONE */
> /home/cdalten/party-2.12/config.h.in:#undef LOCK_NONE
> [cdalten@localhost party-2.12]$
>
> As you can (sort of see), LOCK_LOCKF and LOCK_NONE only appear in the
> header file, configure.h.in and configure.in.
>
> I really don't see what purpose using unused macros would serve in
> this case.
I bet you will get more matches if you grep for 'LOCK' instead of
'LOCK_NONE'.
Think about it for a while. LOCK_NONE is only set by the ./configure
script, it affects party.h through config.h and then the rest of the
program sees a different sort of LOCK() and UNLOCK() macros, depending
on what party.h defined... Does this sound more useful?
| |
| Eric Sosman 2007-05-22, 1:18 am |
| K-mart Cashier wrote:
> On May 21, 6:32 pm, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
>
> Here is what is copied and pasted from my terminal
Much better. Thanks for the corrections.
> #ifdef LOCK_LOCKF
> #ifdef HAVE_SYS_FILE_H
> #include <sys/lockf.h>
> #endif
> #ifdef HAVE_SYS_FILE_H
> #include <sys/file.h>
> #endif
> #define LOCK(file) fseek(file, 0L, 0), lockf(file, 1, 0L)
> #define UNLOCK(file) fseek(file, 0L, 0), lockf(file, 0, 0L)
> #endif /* LOCK_LOCKF */
>
> #ifdef LOCK_LOCKING
> #ifdef HAVE_SYS_LOCKING_H
> #include <sys/locking.h>
> #endif
> #define LOCK(file) fseek(file, 0L, 0), chk_lock(file, 1)
> #define UNLOCK(file) fseek(file, 0L, 0), chk_lock(file, 0)
> #endif /* LOCK_LOCKING */
>
> #ifdef LOCK_NONE
> #define LOCK(file)
> #define UNLOCK(file)
> #endif /* LOCK_NONE */
>
> #ifdef SUID
> #define CHN_MODE 0644
> #define DEP_MODE 0600
> #define USR_MODE 0600
>
> Here is what is my directory
> [cdalten@localhost party-2.12]$ ls
> chantab configure.in INSTALLATION noisetab party.1 partytab
> close.c debug_stty.c install-sh opt.c party.c proc.c
> config.h.in ignore.c Makefile.in opttab.c party.h users.c
> configure input.c makeopt.c output.c partyhlp
> [cdalten@localhost party-2.12]$
>
> And here is what I get when I do a grep
> [cdalten@localhost party-2.12]$ grep -iR LOCK_LOCKF ~/party-2.12
> /home/cdalten/party-2.12/configure.in: [ AC_DEFINE(LOCK_LOCKF)
> /home/cdalten/party-2.12/configure:#define LOCK_LOCKF 1
> /home/cdalten/party-2.12/party.h:#ifdef LOCK_LOCKF
> /home/cdalten/party-2.12/party.h:#endif /* LOCK_LOCKF */
> /home/cdalten/party-2.12/config.h.in:#undef LOCK_LOCKF
>
> [cdalten@localhost party-2.12]$ grep -iR LOCK_NONE ~/party-2.12
> /home/cdalten/party-2.12/configure.in: AC_DEFINE(LOCK_NONE)
> /home/cdalten/party-2.12/configure:#define LOCK_NONE 1
> /home/cdalten/party-2.12/party.h:#ifdef LOCK_NONE
> /home/cdalten/party-2.12/party.h:#endif /* LOCK_NONE */
> /home/cdalten/party-2.12/config.h.in:#undef LOCK_NONE
> [cdalten@localhost party-2.12]$
>
> As you can (sort of see), LOCK_LOCKF and LOCK_NONE only appear in the
> header file, configure.h.in and configure.in.
>
> I really don't see what purpose using unused macros would serve in
> this case.
Well, they're not "unused" at all: They're being tested
with #ifdef directives to alter the way the LOCK and UNLOCK
macros are defined. If LOCK_LOCKF is defined you get one
version of LOCK and UNLOCK, if LOCK_LOCKING is defined you get
another, and if neither is defined you get yet a third. (If both
are defined you get an error; keep your fingers crossed!) The
ultimate purpose seems to be to define LOCK and UNLOCK in a
way that is presumably appropriate for the system at hand: some
systems use lockf(), some use chk_lock(), and some don't support
file locking at all.
Macros like LOCK_LOCKF are variously referred to as "feature
test" or "capability" macros: their definition or non-definition
describes how the system being compiled for accomplishes this or
that task. One could test them explicitly in the main body of
the code, or (as here) use them to control the definition of yet
more macros so they in turn will "do the right thing."
--
Eric Sosman
esosman@acm-dot-org.invalid
| |
| K-mart Cashier 2007-05-22, 1:18 am |
| On May 21, 7:02 pm, Giorgos Keramidas <keram...@ceid.upatras.gr>
wrote:
> On 21 May 2007 18:52:52 -0700, K-mart Cashier <cdal...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
> I bet you will get more matches if you grep for 'LOCK' instead of
> 'LOCK_NONE'.
>
Why yes. Yes I do!
[cdalten@localhost party-2.12]$ grep -iR LOCK ~/party-2.12 | wc -l
152
> Think about it for a while. LOCK_NONE is only set by the ./configure
> script, it affects party.h through config.h and then the rest of the
> program sees a different sort of LOCK() and UNLOCK() macros, depending
> on what party.h defined... Does this sound more useful?
I'm sure it does. However, it's really hurting to think right about
now. I took a personal day from my $11.00/hr clerk job so I could let
the whole BS of "Function Literals" and "statements vs expressions"
sink in. Around 2.00 PM, I had another brain fart. The brain fart just
happened to be about the macros. I really wasn't expecting this
conversation to be this deep. However, I didn't want to hold off and
not post it because I was afraid I might loose my thought.
| |
| Giorgos Keramidas 2007-05-22, 1:25 pm |
| On 21 May 2007 19:29:09 -0700, K-mart Cashier <cdalten@gmail.com> wrote:
>On May 21, 7:02 pm, Giorgos Keramidas <keram...@ceid.upatras.gr> wrote:
>
> Why yes. Yes I do!
> [cdalten@localhost party-2.12]$ grep -iR LOCK ~/party-2.12 | wc -l
> 152
Neat!
>
> I'm sure it does. However, it's really hurting to think right about
> now. I took a personal day from my $11.00/hr clerk job so I could let
> the whole BS of "Function Literals" and "statements vs expressions"
> sink in. Around 2.00 PM, I had another brain fart. The brain fart just
> happened to be about the macros. I really wasn't expecting this
> conversation to be this deep. However, I didn't want to hold off and
> not post it because I was afraid I might loose my thought.
That's ok. No harm done, really 
I'm actually glad this conversation _was_ this deep. Shallow
conversations are kind of boring most of the time.
| |
| K-mart Cashier 2007-05-22, 1:25 pm |
| On May 21, 6:52 pm, K-mart Cashier <cdal...@gmail.com> wrote:
> On May 21, 6:32 pm, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
>
>
>
>
>
>
>
>
>
> Here is what is copied and pasted from my terminal
>
> #ifdef LOCK_LOCKF
> #ifdef HAVE_SYS_FILE_H
> #include <sys/lockf.h>
> #endif
> #ifdef HAVE_SYS_FILE_H
> #include <sys/file.h>
> #endif
> #define LOCK(file) fseek(file, 0L, 0), lockf(file, 1, 0L)
> #define UNLOCK(file) fseek(file, 0L, 0), lockf(file, 0, 0L)
> #endif /* LOCK_LOCKF */
>
> #ifdef LOCK_LOCKING
> #ifdef HAVE_SYS_LOCKING_H
> #include <sys/locking.h>
> #endif
> #define LOCK(file) fseek(file, 0L, 0), chk_lock(file, 1)
> #define UNLOCK(file) fseek(file, 0L, 0), chk_lock(file, 0)
> #endif /* LOCK_LOCKING */
>
> #ifdef LOCK_NONE
> #define LOCK(file)
> #define UNLOCK(file)
> #endif /* LOCK_NONE */
>
> #ifdef SUID
> #define CHN_MODE 0644
> #define DEP_MODE 0600
> #define USR_MODE 0600
>
One last question. Are the macro names like LOCK_LOCKF and
LOCK_LOCKING random names? Ie, could the author have say used LOCK and
LOCKING?
| |
| Barry Margolin 2007-05-23, 1:17 am |
| In article <1179841749.619870.259460@z28g2000prd.googlegroups.com>,
K-mart Cashier <cdalten@gmail.com> wrote:
> One last question. Are the macro names like LOCK_LOCKF and
> LOCK_LOCKING random names? Ie, could the author have say used LOCK and
> LOCKING?
They're arbitrary. Mainly he has to ensure that his macros don't
conflict with the names used in any of the other headers used.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|