Skip to Content.
Sympa Menu

freetds - RE: [freetds] #if or #ifndef

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "'freetds AT lists.ibiblio.org'" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] #if or #ifndef
  • Date: Thu, 13 Feb 2003 10:49:30 -0500

> From: ZIGLIO Frediano [mailto:Frediano.Ziglio AT vodafoneomnitel.it]
> Sent: February 13, 2003 9:26 AM
>
> I'm merging some patch.
> There are many replaces of #ifdef with #if in such way:
> From
> #ifdef DMALLOC
> to
> #if DMALLOC
> What's the right (or better) method ?

Consistency is more important than the choice itself, IMO.

Some data:

$ grep -r --no-file \#if include src |grep -v 'if 0' |perl -ne'
chop;
($if, @macro)=split;
$macro = join " ", @macro;
if(/ifn*def/){
$ifdef{$macro}++;
} else {
$if{$macro}++;
}
$macro{$macro}++;
END{
printf "9999\tif\tifdef\n";
foreach $m (sort keys %macro){
printf "%d\t%d\t%d\t$m$/",
($if{$m}+$ifdef{$m}),
$if{$m}, $ifdef{$m};
}
}' |sort -rn |head -25
9999 if ifdef
121 121 0 HAVE_CONFIG_H
99 98 1 HAVE_STRING_H
82 81 1 HAVE_STDLIB_H
42 0 42 __cplusplus
28 4 24 WORDS_BIGENDIAN
27 0 27 DMALLOC
19 18 1 HAVE_UNISTD_H
18 18 0 (ODBCVER >= 0x0300)
11 11 0 TIME_WITH_SYS_TIME
10 10 0 HAVE_ICONV
7 7 0 HAVE_NETINET_IN_H
7 1 6 MSDBLIB
6 0 6 ENABLE_DEVELOPING
6 6 0 HAVE_ERRNO_H
6 6 0 HAVE_SYS_SOCKET_H
6 0 6 UNIXODBC
6 0 6 _REENTRANT
5 5 0 HAVE_ARPA_INET_H
5 5 0 HAVE_SYS_TYPES_H
4 0 4 MICROSOFT_DBLIB
4 3 1 TDS42
4 0 4 WIN32
3 3 0 (ODBCVER >= 0x300)
3 0 3 COMMON_h

It looks like "HAVE_" macros are clearly in the "if" camp, while DMALLOC is
consistently used with "ifdef". I tend to use #ifdef mostly to prevent
duplicate #includes. Probably a C++ habit.

In the particular case of DMALLOC, I suspect Brian made a careful choice.
DMALLOC replaces malloc(), and you can't have two kinds of heap allocation
in a single program (unless you're *extremely* careful with free()). You
might conceivably want to defeat DMALLOC's behavior in a particular file,
but you wouldn't want to mix allocation schemes.

--jkl


The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the
original message. Please note that we do not accept account orders and/or
instructions by e-mail, and therefore will not be responsible for carrying
out such orders and/or instructions.





  • [freetds] #if or #ifndef, ZIGLIO Frediano, 02/13/2003
    • <Possible follow-up(s)>
    • RE: [freetds] #if or #ifndef, Lowden, James K, 02/13/2003

Archive powered by MHonArc 2.6.24.

Top of Page