consolidate TRUE and FALSE
Subsystems (25)
PATCH 1/1 consolidate TRUE and FALSE
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
In file included from drivers/pci/hotplug/ibmphp_core.c:40:drivers/pci/hotplug/ibmphp.h:409:1: warning: "FALSE" redefined
In file included from include/acpi/acpi.h:55,
from drivers/pci/hotplug/pci_hotplug.h:187,
from drivers/pci/hotplug/ibmphp.h:33,
from drivers/pci/hotplug/ibmphp_core.c:40:include/acpi/actypes.h:336:1: warning: this is the location of the previous definition
The patch implements TRUE and FALSE in include/linux/kernel.h and removes all the private versions.
The patch also kills off a few private implementations of NULL.
Note that the patch also removes TRUE, FALSE and NULL from include/acpi/actypes.h. If this breaks ACPi on non-linux builds I'd suggest that these things should be implemented in an OS-specific ACPI header, not in a generic one. Because this OS now provides TRUE and FALSE and NULL.
Various places are doing things like
typedef {
FALSE,
TRUE
} my_fave_name_for_a_bool;
These are converted to
typedef int my_fave_name_for_a_bool;
---
Documentation/mtrr.txt | 5 ----- arch/alpha/kernel/smc37c669.c | 7 ------- arch/arm/nwfpe/milieu.h | 9 --------- arch/arm26/nwfpe/milieu.h | 9 --------- arch/i386/kernel/cpu/mtrr/mtrr.h | 5 ----- arch/mips/ite-boards/generic/lpc.c | 8 -------- arch/parisc/math-emu/float.h | 2 -- arch/ppc/4xx_io/serial_sicc.c | 7 ------- arch/ppc/boot/common/misc-common.c | 7 ++----- arch/ppc/boot/simple/rw4/stb.h | 11 ----------- drivers/block/z2ram.c | 3 --- drivers/char/ftape/compressor/lzrw3.h | 3 --- drivers/char/mwave/smapi.h | 2 -- drivers/char/rio/rio.h | 7 ------- drivers/char/rio/sam.h | 7 ------- drivers/input/joystick/iforce/iforce.h | 3 --- drivers/isdn/hardware/eicon/platform.h | 12 ------------ drivers/isdn/hisax/hfc_usb.h | 4 ---- drivers/media/radio/radio-gemtek-pci.c | 8 -------- drivers/media/video/cx88/cx88.h | 6 ------ drivers/media/video/saa5246a.h | 5 ----- drivers/media/video/saa5249.c | 5 ----- drivers/media/video/saa7134/saa7134.h | 6 ------ drivers/net/3c505.c | 15 --------------- drivers/net/8139cp.c | 5 ----- drivers/net/dm9000.c | 3 --- drivers/net/e1000/e1000_osdep.h | 7 +------ drivers/net/ixgb/ixgb_osdep.h | 7 +------ drivers/net/oaknet.c | 8 -------- drivers/net/s2io.h | 5 ----- drivers/net/skfp/h/targetos.h | 3 --- drivers/net/tlan.h | 3 --- drivers/net/tokenring/ibmtr.c | 3 --- drivers/net/tulip/de4x5.h | 3 --- drivers/net/wireless/strip.c | 2 -- drivers/net/wireless/wavelan_cs.h | 3 --- drivers/pci/hotplug/ibmphp.h | 2 -- drivers/scsi/advansys.c | 7 ------- drivers/scsi/aic7xxx/aic79xx.h | 7 ------- drivers/scsi/aic7xxx/aic7xxx.h | 7 ------- drivers/scsi/aic7xxx/aicasm/aicasm.h | 8 -------- drivers/scsi/aic7xxx_old.c | 6 ------ drivers/scsi/dpti.h | 6 ------ drivers/scsi/eata_generic.h | 7 ------- drivers/scsi/gdth.h | 7 ------- drivers/scsi/nsp32.h | 6 ------ drivers/scsi/scsi.h | 10 ---------- drivers/scsi/u14-34f.c | 2 -- drivers/scsi/ultrastor.c | 3 --- drivers/telephony/ixj.h | 3 --- drivers/usb/serial/io_edgeport.h | 6 ------ drivers/usb/serial/whiteheat.h | 5 ----- drivers/video/cirrusfb.c | 9 --------- drivers/video/riva/riva_hw.h | 10 ---------- drivers/video/sis/vgatypes.h | 8 -------- fs/cifs/cifsfs.h | 8 -------- fs/cifs/cifsglob.h | 8 -------- fs/cifs/smbencrypt.c | 7 ------- fs/devfs/base.c | 5 ----- fs/jfs/jfs_types.h | 2 -- fs/ntfs/types.h | 5 +---- fs/partitions/ldm.c | 5 +---- include/asm-ppc/gt64260.h | 8 -------- include/linux/agp_backend.h | 8 -------- include/linux/agpgart.h | 8 -------- include/linux/kernel.h | 7 +++++++ include/linux/ps2esdi.h | 3 --- include/linux/synclink.h | 2 -- include/net/irda/irda.h | 8 -------- sound/oss/aedsp16.c | 6 ------ sound/oss/os.h | 3 --- 71 files changed, 13 insertions(+), 407 deletions(-)
arch/alpha/kernel/smc37c669.c renamed from arch/alpha/kernel/smc37c669.c~consolidate-true-and-false +0 -7
@@ -947,13 +947,6 @@ void SMC37c669_display_device_info(#include "cp$src:platform.h" #endif -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#define wb ( _x_, _y_ ) outb( _y_, (unsigned int)((unsigned long)_x_) )#define rb ( _x_ ) inb( (unsigned int)((unsigned long)_x_) )
arch/arm26/nwfpe/milieu.h renamed from arch/arm26/nwfpe/milieu.h~consolidate-true-and-false +0 -11
@@ -35,14 +35,3 @@ Include common integer types and flags.------------------------------------------------------------------------------- */ #include "ARM-gcc.h" - -/* -------------------------------------------------------------------------------- -Symbolic Boolean literals. -------------------------------------------------------------------------------- -*/ -enum { -FALSE =0 , -TRUE =1 -}; -
arch/arm/nwfpe/milieu.h renamed from arch/arm/nwfpe/milieu.h~consolidate-true-and-false +0 -11
@@ -35,14 +35,3 @@ Include common integer types and flags.------------------------------------------------------------------------------- */ #include "ARM-gcc.h" - -/* -------------------------------------------------------------------------------- -Symbolic Boolean literals. -------------------------------------------------------------------------------- -*/ -enum { -FALSE =0 , -TRUE =1 -}; -
arch/i386/kernel/cpu/mtrr/mtrr.h renamed from arch/i386/kernel/cpu/mtrr/mtrr.h~consolidate-true-and-false +0 -5
@@ -2,11 +2,6 @@* local mtrr defines. */ -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -#define MTRRcap_MSR 0x0fe#define MTRRdefType_MSR 0x2ff
arch/mips/ite-boards/generic/lpc.c renamed from arch/mips/ite-boards/generic/lpc.c~consolidate-true-and-false +0 -8
@@ -33,14 +33,6 @@#include <asm/it8712.h> #include <asm/it8172/it8172.h> -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -void LPCEnterMBPnP (void ) {int i;
arch/parisc/math-emu/float.h renamed from arch/parisc/math-emu/float.h~consolidate-true-and-false +0 -2
@@ -392,8 +392,6 @@ typedef struct dblwd dbl_unsigned;#define QUAD_P 113/* Boolean Values etc. */ -#define FALSE 0 -#define TRUE (!FALSE)#define NOT !#define XOR ^
arch/ppc/4xx_io/serial_sicc.c renamed from arch/ppc/4xx_io/serial_sicc.c~consolidate-true-and-false +0 -7
@@ -185,13 +185,6 @@#define SERIAL_SICC_MINOR 1#define SERIAL_SICC_NR 1 -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -/* * Things needed by tty driver */
arch/ppc/boot/common/misc-common.c renamed from arch/ppc/boot/common/misc-common.c~consolidate-true-and-false +2 -5
@@ -287,9 +287,6 @@ puthex(unsigned long val)puts (buf); } -#define FALSE 0 -#define TRUE 1 -void _printk (char const *fmt, ...) {
@@ -323,11 +320,11 @@ _vprintk(void(*putc)(const char), const }if (c =='0' ) { - zero_fill = TRUE; + zero_fill =1 ; c = *fmt0++; }else { - zero_fill = FALSE; + zero_fill =0 ; }while (is_digit (c)) {
arch/ppc/boot/simple/rw4/stb.h renamed from arch/ppc/boot/simple/rw4/stb.h~consolidate-true-and-false +0 -11
@@ -225,15 +225,4 @@#define STB_SDRAM_BASE_ADDRESS 0xA0000000#endif -/*----------------------------------------------------------------------------+ -| Other common defines. -+----------------------------------------------------------------------------*/ -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -#endif /* _stb_h_ */
Documentation/mtrr.txt renamed from Documentation/mtrr.txt~consolidate-true-and-false +0 -5
@@ -147,11 +147,8 @@ Reading MTRRs from a C program using ioc #define MTRR_NEED_STRINGS #include <asm/mtrr.h> -#define TRUE 1 -#define FALSE 0 #define ERRSTRING strerror (errno) - int main () { int fd;
@@ -235,8 +232,6 @@ Creating MTRRs from a C programme using #define MTRR_NEED_STRINGS #include <asm/mtrr.h> -#define TRUE 1 -#define FALSE 0 #define ERRSTRING strerror (errno)
drivers/block/z2ram.c renamed from drivers/block/z2ram.c~consolidate-true-and-false +0 -3
@@ -44,9 +44,6 @@extern int m68k_realnum_memory;extern struct mem_info m68k_memory[NUM_MEMINFO ]; -#define TRUE (1) -#define FALSE (0) -#define Z2MINOR_COMBINED (0)#define Z2MINOR_Z2ONLY (1)#define Z2MINOR_CHIPONLY (2)
drivers/char/ftape/compressor/lzrw3.h renamed from drivers/char/ftape/compressor/lzrw3.h~consolidate-true-and-false +0 -3
@@ -168,9 +168,6 @@#define FOPEN_BINARY_WRITE not used/* Mode string for binary writing. */ #define FOPEN_TEXT_APPEND not used/* Mode string for text appending. */ #define REAL not used/* USed for floating point stuff. */ -#ifndef TRUE -#define TRUE 1 -#endif #endif #define DONE_PORT /* Don't do all this again. */
drivers/char/mwave/smapi.h renamed from drivers/char/mwave/smapi.h~consolidate-true-and-false +0 -2
@@ -49,8 +49,6 @@ #ifndef _LINUX_SMAPI_H #define _LINUX_SMAPI_H -#define TRUE 1 -#define FALSE 0 #define BOOLEAN int typedef struct {
drivers/char/rio/rio.h renamed from drivers/char/rio/rio.h~consolidate-true-and-false +0 -7
@@ -221,13 +221,6 @@ typedef struct DbInf {char Name[8 ]; } DbInf; -#ifndef TRUE -#define TRUE (1==1) -#endif -#ifndef FALSE -#define FALSE (!TRUE) -#endif -#define CSUM (pkt_ptr) (((ushort *)(pkt_ptr))[0] + ((ushort *)(pkt_ptr))[1] + \ ((ushort *)(pkt_ptr))[2] + ((ushort *)(pkt_ptr))[3] + \ ((ushort *)(pkt_ptr))[4] + ((ushort *)(pkt_ptr))[5] + \
drivers/char/rio/sam.h renamed from drivers/char/rio/sam.h~consolidate-true-and-false +0 -7
@@ -45,13 +45,6 @@#define NUM_FREE_LIST_UNITS 500 -#ifndef FALSE -#define FALSE (short) 0x00 -#endif -#ifndef TRUE -#define TRUE (short) !FALSE -#endif -#define TX TRUE#define RX FALSE
drivers/input/joystick/iforce/iforce.h renamed from drivers/input/joystick/iforce/iforce.h~consolidate-true-and-false +0 -3
@@ -51,9 +51,6 @@#define IFORCE_232 1#define IFORCE_USB 2 -#define FALSE 0 -#define TRUE 1 -#define FF_EFFECTS_MAX 32/* Each force feedback effect is made of one core effect, which can be
drivers/isdn/hardware/eicon/platform.h renamed from drivers/isdn/hardware/eicon/platform.h~consolidate-true-and-false +0 -12
@@ -72,18 +72,6 @@#define qword u64#endif -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef NULL -#define NULL ((void *) 0) -#endif -#ifndef MIN #define MIN (a,b) ((a)>(b) ? (b) : (a))#endif
drivers/isdn/hisax/hfc_usb.h renamed from drivers/isdn/hisax/hfc_usb.h~consolidate-true-and-false +0 -4
@@ -12,10 +12,6 @@#define VERBOSE_USB_DEBUG -#define TRUE 1 -#define FALSE 0 - -/***********/ /* defines */ /***********/
drivers/media/radio/radio-gemtek-pci.c renamed from drivers/media/radio/radio-gemtek-pci.c~consolidate-true-and-false +0 -8
@@ -65,14 +65,6 @@#define GEMTEK_PCI_RANGE_HIGH (108*16000)#endif -#ifndef TRUE -#define TRUE (1) -#endif - -#ifndef FALSE -#define FALSE (0) -#endif -struct gemtek_pci_card {struct video_device *videodev;
drivers/media/video/cx88/cx88.h renamed from drivers/media/video/cx88/cx88.h~consolidate-true-and-false +0 -6
@@ -37,12 +37,6 @@#include <linux/version.h> #define CX88_VERSION_CODE KERNEL_VERSION(0,0,5) -#ifndef TRUE -# define TRUE (1==1) -#endif -#ifndef FALSE -# define FALSE (1==0) -#endif #define UNSET (-1U)#define CX88_MAXBOARDS 8
drivers/media/video/saa5246a.h renamed from drivers/media/video/saa5246a.h~consolidate-true-and-false +0 -5
@@ -53,11 +53,6 @@ ((p_req)->start <=POS_HEADER_END && \ (p_req)->end >=POS_HEADER_START ) -#ifndef FALSE -#define FALSE 0 -#define TRUE 1 -#endif -/*****************************************************************************/ /* Mode register numbers of the SAA5246A */ /*****************************************************************************/
drivers/media/video/saa5249.c renamed from drivers/media/video/saa5249.c~consolidate-true-and-false +0 -5
@@ -121,11 +121,6 @@ struct saa5249_device/* General defines and debugging support */ -#ifndef FALSE -#define FALSE 0 -#define TRUE 1 -#endif -#define RESCHED do { cond_resched(); } while(0)static struct video_device saa_template;/* Declared near bottom */
drivers/media/video/saa7134/saa7134.h renamed from drivers/media/video/saa7134/saa7134.h~consolidate-true-and-false +0 -6
@@ -42,12 +42,6 @@#include <sound/pcm.h> #include <media/video-buf-dvb.h> -#ifndef TRUE -# define TRUE (1==1) -#endif -#ifndef FALSE -# define FALSE (1==0) -#endif #define UNSET (-1U)/* ----------------------------------------------------------- */
drivers/net/3c505.c renamed from drivers/net/3c505.c~consolidate-true-and-false +0 -15
@@ -169,21 +169,6 @@ static int elp_debug;/***************************************************************** * -* useful macros -* -*****************************************************************/ - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - - -/***************************************************************** -* * List of I/O-addresses we try to auto-sense * Last element MUST BE 0! *****************************************************************/
drivers/net/8139cp.c renamed from drivers/net/8139cp.c~consolidate-true-and-false +0 -5
@@ -108,11 +108,6 @@ MODULE_PARM_DESC (multicast_filter_limit#define PFX DRV_NAME ": " -#ifndef TRUE -#define FALSE 0 -#define TRUE (!FALSE) -#endif -#define CP_DEF_MSG_ENABLE (NETIF_MSG_DRV | \ NETIF_MSG_PROBE | \ NETIF_MSG_LINK)
drivers/net/dm9000.c renamed from drivers/net/dm9000.c~consolidate-true-and-false +0 -3
@@ -77,9 +77,6 @@#define DM9000_PHY 0x40/* PHY address 0x01 */ -#define TRUE 1 -#define FALSE 0 -#define CARDNAME "dm9000"#define PFX CARDNAME ": "
drivers/net/e1000/e1000_osdep.h renamed from drivers/net/e1000/e1000_osdep.h~consolidate-true-and-false +1 -6
@@ -60,12 +60,7 @@#define PCI_COMMAND_REGISTER PCI_COMMAND#define CMD_MEM_WRT_INVALIDATE PCI_COMMAND_INVALIDATE -typedef enum { -#undef FALSE - FALSE = 0, -#undef TRUE - TRUE = 1 -}boolean_t ; +typedef int boolean_t ;#define MSGOUT (S ,A ,B ) printk(KERN_DEBUG S "\n", A, B)
drivers/net/ixgb/ixgb_osdep.h renamed from drivers/net/ixgb/ixgb_osdep.h~consolidate-true-and-false +1 -6
@@ -52,12 +52,7 @@#define PCI_COMMAND_REGISTER PCI_COMMAND#define CMD_MEM_WRT_INVALIDATE PCI_COMMAND_INVALIDATE -typedef enum { -#undef FALSE - FALSE = 0, -#undef TRUE - TRUE = 1 -}boolean_t ; +typedef int boolean_t ;#undef ASSERT#define ASSERT (x) if(!(x)) BUG()
drivers/net/oaknet.c renamed from drivers/net/oaknet.c~consolidate-true-and-false +0 -8
@@ -29,14 +29,6 @@/* Preprocessor Defines */ -#if !defined(TRUE ) ||TRUE !=1 -#define TRUE 1 -#endif - -#if !defined(FALSE ) ||FALSE !=0 -#define FALSE 0 -#endif -#define OAKNET_START_PG 0x20/* First page of TX buffer */ #define OAKNET_STOP_PG 0x40/* Last pagge +1 of RX ring */
drivers/net/s2io.h renamed from drivers/net/s2io.h~consolidate-true-and-false +0 -5
@@ -22,11 +22,6 @@#define BOOL int#endif -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -#undef SUCCESS#define SUCCESS 0#define FAILURE -1
drivers/net/skfp/h/targetos.h renamed from drivers/net/skfp/h/targetos.h~consolidate-true-and-false +0 -3
@@ -60,9 +60,6 @@#include "h/hwmtm.h" -#define TRUE 1 -#define FALSE 0 -// HWM Definitions // ----------------------- #define FDDI_TRACE (string, arg1, arg2, arg3)// Performance analysis.
drivers/net/tlan.h renamed from drivers/net/tlan.h~consolidate-true-and-false +0 -3
@@ -33,9 +33,6 @@* ****************************************************************/ -#define FALSE 0 -#define TRUE 1 -#define TLAN_MIN_FRAME_SIZE 64#define TLAN_MAX_FRAME_SIZE 1600
drivers/net/tokenring/ibmtr.c renamed from drivers/net/tokenring/ibmtr.c~consolidate-true-and-false +0 -3
@@ -116,9 +116,6 @@ in the event that chatty debug messages#define ENABLE_PAGING 1#endif -#define FALSE 0 -#define TRUE (!FALSE) -/* changes the output format of driver initialization */ #define TR_VERBOSE 0
drivers/net/tulip/de4x5.h renamed from drivers/net/tulip/de4x5.h~consolidate-true-and-false +0 -3
@@ -896,10 +896,7 @@** Booleans */ #define NO 0 -#define FALSE 0 -#define YES ~0 -#define TRUE ~0/* ** Adapter state
drivers/net/wireless/strip.c renamed from drivers/net/wireless/strip.c~consolidate-true-and-false +0 -2
@@ -178,8 +178,6 @@ typedef struct {MetricomNode node[NODE_TABLE_SIZE ]; } MetricomNodeTable; -enum {FALSE =0 ,TRUE =1 }; -/* * Holds the radio's firmware version. */
drivers/net/wireless/wavelan_cs.h renamed from drivers/net/wireless/wavelan_cs.h~consolidate-true-and-false +0 -3
@@ -151,9 +151,6 @@ static const int fixed_bands[] = { 915e6#define RX_SIZE (TX_BASE-RX_BASE)/* Size of receive area */ #define RX_SIZE_SHIFT 6/* Bits to shift in stop register */ -#define TRUE 1 -#define FALSE 0 -#define MOD_ENAL 1#define MOD_PROM 2
drivers/pci/hotplug/ibmphp.h renamed from drivers/pci/hotplug/ibmphp.h~consolidate-true-and-false +0 -2
@@ -406,8 +406,6 @@ extern void ibmphp_hpc_stop_poll_thread//---------------------------------------------------------------------------- // HPC return codes //---------------------------------------------------------------------------- -#define FALSE 0x00 -#define TRUE 0x01#define HPC_ERROR 0xFF//-----------------------------------------------------------------------------
drivers/scsi/advansys.c renamed from drivers/scsi/advansys.c~consolidate-true-and-false +0 -7
@@ -865,13 +865,6 @@typedef unsigned char uchar ; -#ifndef TRUE -#define TRUE (1) -#endif -#ifndef FALSE -#define FALSE (0) -#endif -#define EOF (-1)#define ERR (-1)#define UW_ERR (uint)(0xFFFF)
drivers/scsi/aic7xxx/aic79xx.h renamed from drivers/scsi/aic7xxx/aic79xx.h~consolidate-true-and-false +0 -7
@@ -61,13 +61,6 @@ struct scb_platform_data;#define MIN (a,b) (((a) < (b)) ? (a) : (b))#endif -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#define NUM_ELEMENTS (array) (sizeof(array) / sizeof(*array))#define ALL_CHANNELS '\0'
drivers/scsi/aic7xxx/aic7xxx.h renamed from drivers/scsi/aic7xxx/aic7xxx.h~consolidate-true-and-false +0 -7
@@ -62,13 +62,6 @@ struct seeprom_descriptor;#define MIN (a,b) (((a) < (b)) ? (a) : (b))#endif -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#define NUM_ELEMENTS (array) (sizeof(array) / sizeof(*array))#define ALL_CHANNELS '\0'
drivers/scsi/aic7xxx/aicasm/aicasm.h renamed from drivers/scsi/aic7xxx/aicasm/aicasm.h~consolidate-true-and-false +0 -8
@@ -48,14 +48,6 @@#include <sys/queue.h> #endif -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - typedef struct path_entry { char *directory; int quoted_includes_only;
drivers/scsi/aic7xxx_old.c renamed from drivers/scsi/aic7xxx_old.c~consolidate-true-and-false +0 -6
@@ -258,12 +258,6 @@#define ALL_LUNS -1#define MAX_TARGETS 16#define MAX_LUNS 8 -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)# define MMAPIO
drivers/scsi/dpti.h renamed from drivers/scsi/dpti.h~consolidate-true-and-false +0 -6
@@ -158,12 +158,6 @@ static int adpt_device_reset(struct scsi#define I2O_SCSI_DSC_BUS_BUSY 0x3F00#define I2O_SCSI_DSC_QUEUE_FROZEN 0x4000 - -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -#define HBA_FLAGS_INSTALLED_B 0x00000001 // Adapter Was Installed#define HBA_FLAGS_BLINKLED_B 0x00000002 // Adapter In Blink LED State#define HBA_FLAGS_IN_RESET 0x00000040/* in reset */
drivers/scsi/eata_generic.h renamed from drivers/scsi/eata_generic.h~consolidate-true-and-false +0 -7
@@ -18,13 +18,6 @@* Misc. definitions * *********************************************/ -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#define R_LIMIT 0x20000#define MAXISA 4
drivers/scsi/gdth.h renamed from drivers/scsi/gdth.h~consolidate-true-and-false +0 -7
@@ -16,13 +16,6 @@#include <linux/version.h> #include <linux/types.h> -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -/* defines, macros */ /* driver version */
drivers/scsi/nsp32.h renamed from drivers/scsi/nsp32.h~consolidate-true-and-false +0 -6
@@ -76,12 +76,6 @@ typedef u16 u16_le;/* * BASIC Definitions */ -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif #define ASSERT 1#define NEGATE 0
drivers/scsi/scsi.h renamed from drivers/scsi/scsi.h~consolidate-true-and-false +0 -10
@@ -29,16 +29,6 @@#include <scsi/scsi_tcq.h> #include <scsi/scsi.h> -/* -* Some defs, in case these are not defined elsewhere. -*/ -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -struct Scsi_Host ;struct scsi_cmnd ;struct scsi_device ;
drivers/scsi/u14-34f.c renamed from drivers/scsi/u14-34f.c~consolidate-true-and-false +0 -2
@@ -502,8 +502,6 @@ static struct scsi_host_template driver_#define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)#define SKIP ULONG_MAX -#define FALSE 0 -#define TRUE 1#define FREE 0#define IN_USE 1#define LOCKED 2
drivers/scsi/ultrastor.c renamed from drivers/scsi/ultrastor.c~consolidate-true-and-false +0 -3
@@ -148,9 +148,6 @@#include <scsi/scsi_host.h> #include "ultrastor.h" -#define FALSE 0 -#define TRUE 1 -#ifndef ULTRASTOR_DEBUG #define ULTRASTOR_DEBUG (UD_ABORT|UD_CSIR|UD_RESET)#endif
drivers/telephony/ixj.h renamed from drivers/telephony/ixj.h~consolidate-true-and-false +0 -3
@@ -54,9 +54,6 @@ typedef __u8 BOOL;#define IXJMAX 16#endif -#define TRUE 1 -#define FALSE 0 -/****************************************************************************** * * This structure when unioned with the structures below makes simple byte
drivers/usb/serial/io_edgeport.h renamed from drivers/usb/serial/io_edgeport.h~consolidate-true-and-false +0 -6
@@ -19,12 +19,6 @@#define MAX_RS232_PORTS 8/* Max # of RS-232 ports per device */ /* typedefs that the insideout headers need */ -#ifndef TRUE -#define TRUE (1) -#endif -#ifndef FALSE -#define FALSE (0) -#endif #ifndef LOW8 #define LOW8 (a) ((unsigned char)(a & 0xff))#endif
drivers/usb/serial/whiteheat.h renamed from drivers/usb/serial/whiteheat.h~consolidate-true-and-false +0 -5
@@ -19,11 +19,6 @@#ifndef __LINUX_USB_SERIAL_WHITEHEAT_H#define __LINUX_USB_SERIAL_WHITEHEAT_H - -#define FALSE 0 -#define TRUE 1 - -/* WhiteHEAT commands */ #define WHITEHEAT_OPEN 1/* open the port */ #define WHITEHEAT_CLOSE 2/* close the port */
drivers/video/cirrusfb.c renamed from drivers/video/cirrusfb.c~consolidate-true-and-false +0 -9
@@ -100,15 +100,6 @@#define assert (expr)#endif -#ifdef TRUE -#undef TRUE -#endif -#ifdef FALSE -#undef FALSE -#endif -#define TRUE 1 -#define FALSE 0 -#define MB_ (1024*1024)#define KB_ (1024)
drivers/video/riva/riva_hw.h renamed from drivers/video/riva/riva_hw.h~consolidate-true-and-false +0 -10
@@ -53,16 +53,6 @@typedef int Bool ;#endif -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef NULL -#define NULL 0 -#endif -/* * Typedefs to force certain sized values. */
drivers/video/sis/vgatypes.h renamed from drivers/video/sis/vgatypes.h~consolidate-true-and-false +0 -8
@@ -57,14 +57,6 @@#include <linux/version.h> #endif -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef BOOLEAN typedef unsigned int BOOLEAN ;#endif
fs/cifs/cifsfs.h renamed from fs/cifs/cifsfs.h~consolidate-true-and-false +0 -8
@@ -24,14 +24,6 @@#define ROOT_I 2 -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif -extern struct address_space_operations cifs_addr_ops;/* Functions related to super block operations */
fs/cifs/cifsglob.h renamed from fs/cifs/cifsglob.h~consolidate-true-and-false +0 -8
@@ -55,14 +55,6 @@#include "cifspdu.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef XATTR_DOS_ATTRIB #define XATTR_DOS_ATTRIB "user.DOSATTRIB"#endif
fs/cifs/smbencrypt.c renamed from fs/cifs/smbencrypt.c~consolidate-true-and-false +0 -7
@@ -34,13 +34,6 @@#include "cifs_debug.h" #include "cifsencrypt.h" -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif -/* following came from the other byteorder.h to avoid include conflicts */ #define CVAL (buf,pos) (((unsigned char *)(buf))[pos])#define SSVALX (buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
fs/devfs/base.c renamed from fs/devfs/base.c~consolidate-true-and-false +0 -5
@@ -697,11 +697,6 @@#define POISON_PTR ( *(void **) poison_array )#define MAGIC_VALUE 0x327db823 -#ifndef TRUE -# define TRUE 1 -# define FALSE 0 -#endif -#define MODE_DIR (S_IFDIR | S_IWUSR | S_IRUGO | S_IXUGO)#define DEBUG_NONE 0x0000000
fs/jfs/jfs_types.h renamed from fs/jfs/jfs_types.h~consolidate-true-and-false +0 -2
@@ -58,8 +58,6 @@ struct timestruc_t {#define ONES 0xffffffffu/* all bit on */ typedef int boolean_t ; -#define TRUE 1 -#define FALSE 0/* * logical xd (lxd)
fs/ntfs/types.h renamed from fs/ntfs/types.h~consolidate-true-and-false +1 -4
@@ -61,10 +61,7 @@ typedef sle64 leLSN;typedef s64 USN ;typedef sle64 leUSN ; -typedef enum { -FALSE =0 , -TRUE =1 -}BOOL ; +typedef int BOOL ; typedef enum { CASE_SENSITIVE = 0,
fs/partitions/ldm.c renamed from fs/partitions/ldm.c~consolidate-true-and-false +1 -4
@@ -30,10 +30,7 @@#include "check.h" #include "msdos.h" -typedef enum { -FALSE =0 , -TRUE =1 -}BOOL ; +typedef int BOOL ;/** * ldm_debug/info/error/crit - Output an error message
include/asm-ppc/gt64260.h renamed from include/asm-ppc/gt64260.h~consolidate-true-and-false +0 -8
@@ -32,14 +32,6 @@ extern u32 gt64260_irq_base; /*extern u32 gt64260_revision;extern u8 gt64260_pci_exclude_bridge; -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -/* IRQs defined by the 64260 */ #define GT64260_IRQ_MPSC0 40#define GT64260_IRQ_MPSC1 42
include/linux/agp_backend.h renamed from include/linux/agp_backend.h~consolidate-true-and-false +0 -8
@@ -32,14 +32,6 @@#ifdef __KERNEL__ -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -enum chipset_type {NOT_SUPPORTED , SUPPORTED,
include/linux/agpgart.h renamed from include/linux/agpgart.h~consolidate-true-and-false +0 -8
@@ -43,14 +43,6 @@#define AGP_DEVICE "/dev/agpgart" -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef __KERNEL__#include <linux/types.h> #include <asm/types.h>
include/linux/kernel.h renamed from include/linux/kernel.h~consolidate-true-and-false +7 -0
@@ -18,6 +18,13 @@extern const char linux_banner[]; +/* +* Give these a funny-looking definition to improve the chances of them +* clashing with other definitions of TRUE and FALSE, causing a cpp error +*/ +#define TRUE ((1)) +#define FALSE ((0)) +#define INT_MAX ((int)(~0U>>1))#define INT_MIN (-INT_MAX - 1)#define UINT_MAX (~0U)
include/linux/ps2esdi.h renamed from include/linux/ps2esdi.h~consolidate-true-and-false +0 -3
@@ -85,9 +85,6 @@#define HDIO_GETGEO 0x0301 -#define FALSE 0 -#define TRUE !FALSE -struct ps2esdi_geometry {unsigned char heads;unsigned char sectors;
include/linux/synclink.h renamed from include/linux/synclink.h~consolidate-true-and-false +0 -2
@@ -14,8 +14,6 @@#define SYNCLINK_H_VERSION 3.6#define BOOLEAN int -#define TRUE 1 -#define FALSE 0#define BIT0 0x0001#define BIT1 0x0002
include/net/irda/irda.h renamed from include/net/irda/irda.h~consolidate-true-and-false +0 -8
@@ -34,14 +34,6 @@typedef __u32 magic_t ; -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -/* Hack to do small backoff when setting media busy in IrLAP */ #ifndef SMALL #define SMALL 5
sound/oss/aedsp16.c renamed from sound/oss/aedsp16.c~consolidate-true-and-false +0 -6
@@ -274,12 +274,6 @@#endif /* -* Misc definitions -*/ -#define TRUE 1 -#define FALSE 0 - -/* * Region Size for request/check/release region. */ #define IOBASE_REGION_SIZE 0x10
sound/oss/os.h renamed from sound/oss/os.h~consolidate-true-and-false +0 -3
@@ -25,9 +25,6 @@#include <linux/soundcard.h> -#define FALSE 0 -#define TRUE 1 -extern int sound_alloc_dma (int chn,char *deviceID);extern int sound_open_dma (int chn,char *deviceID);extern void sound_free_dma (int chn);
_
Hi,
Quoted 4 lines · On Thu, 16 Mar 2006, [email protected] wrote:
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
[snip
Quoted 3 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.
Great! That has really been long overdue.
Quoted 10 lines
Various places are doing things like
typedef {
FALSE,
TRUE
}my_fave_name_for_a_bool;These are converted to
typedef int
my_fave_name_for_a_bool;
Given that the kernel now requires gcc 3.2 or later, that already includes a native boolean type (_Bool)? Why not use that instead of "int"?
Also <stdbool.h> contains:
#define bool _Bool
#define true 1
#define false 0
So we could take the bool rather than _Bool, too given _Bool looks rather ugly...
We could even go as far as removing all those typedefs and replacing all their uses with the native boolean type (or the "bool" define or whatever). Seems like the perfect janitorial task to me. (-;
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Quoted 8 lines · Anton Altaparmakov
Quoted 8 lines
Various places are doing things like
typedef {
FALSE,
TRUE
}my_fave_name_for_a_bool;
Quoted 6 lines
Quoted 3 lines
These are converted to
typedef int
my_fave_name_for_a_bool;Given that the kernel now requires gcc 3.2 or later, that already includes a native boolean type (
_Bool)?
It does?
Is it any good?
bix:/home/akpm> cat t.c
void foo()
{
_Bool b = 1;
b += 2;
}bix:/home/akpm> gcc -O -Wall -c t.c
bix:/home/akpm>
Sigh.
Quoted 1 line
Why not use that instead of "int"?
That'd be a separate patch ;)
Quoted 8 lines
Also <
stdbool.h> contains:#define bool
_Bool
#define true 1
#define false 0So we could take the bool rather than
_Bool, too given_Boollooks rather ugly...
We have a couple of private bools and a couple of private 'true's and `false's so I guess it'd be a simple patch. I wonder if it would have any surprising side-effects.
(I think using `bool' is a good thing - it makes the code more readable. It's a shame the compiler's handling of it is so useless).
Quoted 27 lines · Andrew Morton
Quoted 8 lines · Anton Altaparmakov
Quoted 8 lines
Various places are doing things like
typedef {
FALSE,
TRUE
}my_fave_name_for_a_bool;Quoted 6 lines
Quoted 3 lines
These are converted to
typedef int
my_fave_name_for_a_bool;Given that the kernel now requires gcc 3.2 or later, that already includes a native boolean type (
_Bool)?It does?
Is it any good?
bix:/home/akpm> cat
t.c
voidfoo(){ _Bool b = 1; b += 2; }
Quoted 5 lines
bix:/home/akpm> gcc -O -Wall -c
t.c
bix:/home/akpm>Sigh.
If you were to read the value of b after "b += 2", you'd find that b is still 1.
Also note that _Bool is a byte, so anything that exposed its own custom boolean type to userspace needs to be carefully updated.
Signature · 1 line
Nicholas Miell <[email protected]>
Quoted 3 lines
Is it any good?
Depends.
20:51 shanghai:/dev/shm > cat bool.c
#include <stdio.h>
int main(void) {
_Bool x = 0;
x += 2;
printf("%d\n", x);
}
20:51 shanghai:/dev/shm > gcc bool.c && ./a.out
1It can't "overflow". If that's good or not I can't tell, and I can only imagine an artifical scenario where it affects things:
void do_something_wrong(int *x) {
*x += 2;
}
int x = 0;
do_something_wrong(&x);
if(x & 1)
printf("x & 1");Quoted 1 line
From this one, we would expect nothing to be printed. But if x was a
_Bool
x (and _Bool *x, respectively), something would be printed.
Jan Engelhardt
Quoted 4 lines · On Thu, 2006-03-16 at 02:01 -0800, [email protected] wrote:
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
makes me wonder how many of these users should actually just use 0 and 1 directly (but that's a long during janitor task I guess)
Quoted 4 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.The patch also kills off a few private implementations of NULL.
NACK. Just kill them all and use 0/1
Quoted 6 lines · On Thu, 16 Mar 2006 16:01:30 +0000 Christoph Hellwig wrote:
Quoted 4 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.The patch also kills off a few private implementations of NULL.
NACK. Just kill them all and use 0/1
nah, the only place that using symbolic names for true and false is a problem is when someone #defines or enums them bassackwards.
---
~Randy
Quoted 11 lines · Randy.Dunlap
Quoted 6 lines · On Thu, 16 Mar 2006 16:01:30 +0000 Christoph Hellwig wrote:
Quoted 4 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.The patch also kills off a few private implementations of NULL.
NACK. Just kill them all and use 0/1
nah, the only place that using symbolic names for true and false is a problem is when someone #defines or enums them bassackwards.
it makes the code longer and harder to read. there's a reason the core code doesn't use it, and the periphal code should do the same.
Quoted 8 lines · On Thu, 16 Mar 2006 16:30:01 +0000 Christoph Hellwig wrote:
Quoted 7 lines · Randy.Dunlap
Quoted 5 lines · On Thu, 16 Mar 2006 16:01:30 +0000 Christoph Hellwig wrote:
Quoted 4 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.The patch also kills off a few private implementations of NULL.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
NACK. Just kill them all and use 0/1
nah, the only place that using symbolic names for true and false is a problem is when someone #defines or enums them bassackwards.
it makes the code longer and harder to read. there's a reason the core code doesn't use it, and the periphal code should do the same.
in your opinion.
---
~Randy
Quoted 4 lines
Quoted 2 lines
it makes the code longer and harder to read. there's a reason the core code doesn't use it, and the periphal code should do the same.
in your opinion.
of course. but that it's not used in core code implies this opinion is widely shared.
Quoted 7 lines · On Thu, 16 Mar 2006 16:36:21 +0000 Christoph Hellwig wrote:
Quoted 4 lines
Quoted 2 lines
it makes the code longer and harder to read. there's a reason the core code doesn't use it, and the periphal code should do the same.
in your opinion.
of course. but that it's not used in core code implies this opinion is widely shared.
well I'll be happy to leave it up to Andrew to work out. :)
---
~Randy
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines
Quoted 2 lines
it makes the code longer and harder to read. there's a reason the core code doesn't use it, and the periphal code should do the same.
in your opinion.
of course. but that it's not used in core code implies this opinion is widely shared.
Again, in your opinion. To me it is a simple consequence of there not being a boolean type in the kernel so you cannot use it in the core code. Once there is such a type I would imagine users will appear in the core code over time.
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Quoted 4 lines · Anton Altaparmakov
Again, in your opinion. To me it is a simple consequence of there not being a boolean type in the kernel so you cannot use it in the core code. Once there is such a type I would imagine users will appear in the core code over time.
And that's supposed to be an argument in favour of that crap?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Ray Lee
Quoted 1 line
And that's supposed to be an argument in favour of that crap?
So an honest, if stupid, question: How is the TRUE/FALSE stuff any different than the case of using a NULL when assigning a zero to a pointer is explicitly required to have the same effect? They both seem to further the goal of better self-documenting code.
NULL is idiomatic in C. TRUE and FALSE are definitely not. Again, if you want Bournegol, you know where to find it. Grab the v7 sh and enjoy "self-documenting" code.
Quoted 7 lines · Al Viro
Quoted 4 lines · Anton Altaparmakov
Again, in your opinion. To me it is a simple consequence of there not being a boolean type in the kernel so you cannot use it in the core code. Once there is such a type I would imagine users will appear in the core code over time.
And that's supposed to be an argument in favour of that crap?
No, it was an alternative interpretation to Christoph's statement that the non-use of booleans was due to them being crap. So I said that you can't use what you don't have and I imagine the majority of people do not want these pointless flamewars so no-one has so far bothered to introduce a generic bollean type in the kernel...
Andy why is it crap? For a start it is valid C (well, ok C99, but even you are fond of a lot of C99 features like the initializers) and second it makes code more readable and makes meaning of functions a lot more obvious, e.g reading:
"extern bool foo_is_compressed(bar);"
in a header file makes it damn obvious that if foo_is_compressed() returns "true" then "bar" is compressed and if it returns "false" then "bar" is not compressed.
If you see:
"extern int foo_is_compressed(bar);"
You have to go find the .c file containing the function and read it to figure out what the heck the return value means/is. And don't tell me you can rely on it returning 0 for not-compressed and 1 for compressed. For a start it could return < 0 for error and a myriad of other things. Especially in the kernel core the functions like that seem to randomly return 0 for true and 1 for false and worse. But even if they were consistent you could never rule out the < 0 for error case unless you read the function itself.
So I beg to differ with your opinion of boolean type being crap.
As you might have noticed already, I think booleans have their place and make code much more readable when used appropriately. I have only been programming for the last 24 years and I like booleans and no-one is going to get me to think otherwise after such a long time...
I am happy to agree that we disagree. Just stay away with s/true/1/ and s/false/0/ conversions from fs/ntfs/ please and I will shut up... (-:
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Quoted 9 lines · Anton Altaparmakov
Quoted 7 lines · Al Viro
Quoted 4 lines · Anton Altaparmakov
Again, in your opinion. To me it is a simple consequence of there not being a boolean type in the kernel so you cannot use it in the core code. Once there is such a type I would imagine users will appear in the core code over time.
And that's supposed to be an argument in favour of that crap?
Quoted 7 lines
No, it was an alternative interpretation to Christoph's statement that the non-use of booleans was due to them being crap. So I said that you can't use what you don't have and I imagine the majority of people do not want these pointless flamewars so no-one has so far bothered to introduce a generic bollean type in the kernel...
Andy why is it crap? For a start it is valid C (well, ok C99, but even
s/Andy/And/...
Quoted 30 lines
you are fond of a lot of C99 features like the initializers) and second it makes code more readable and makes meaning of functions a lot more obvious, e.g reading:
"extern bool
foo_is_compressed(bar);"in a header file makes it damn obvious that if
foo_is_compressed()returns "true" then "bar" is compressed and if it returns "false" then "bar" is not compressed.If you see:
"extern int
foo_is_compressed(bar);"You have to go find the .c file containing the function and read it to figure out what the heck the return value means/is. And don't tell me you can rely on it returning 0 for not-compressed and 1 for compressed. For a start it could return < 0 for error and a myriad of other things. Especially in the kernel core the functions like that seem to randomly return 0 for true and 1 for false and worse. But even if they were consistent you could never rule out the < 0 for error case unless you read the function itself.
So I beg to differ with your opinion of boolean type being crap.
As you might have noticed already, I think booleans have their place and make code much more readable when used appropriately. I have only been programming for the last 24 years and I like booleans and no-one is going to get me to think otherwise after such a long time...
Quoted 7 lines
I am happy to agree that we disagree. Just stay away with s/true/1/ and s/false/0/ conversions from
fs/ntfs/please and I will shut up... (-:Best regards,
Anton
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Quoted 5 lines
Quoted 2 lines
of course. but that it's not used in core code implies this opinion is widely shared.
[...] To me it is a simple consequence of there not
being a boolean type in the kernel so you cannot use it in the core code.
typedef bool int;
And then happily use if(EXPR) and if(!EXPR) instead of if(EXPR == TRUE) or if(EXPR == FALSE). :-)
But typedeffing it to int (or unsigned char, if someone likes that for space optimization) does not "catch overflows" (see another lkml mail from me) as _Bool would.
Jan Engelhardt
Quoted 7 lines · Jan Engelhardt
Quoted 5 lines
Quoted 2 lines
of course. but that it's not used in core code implies this opinion is widely shared.
[...] To me it is a simple consequence of there not
being a boolean type in the kernel so you cannot use it in the core code.typedef bool int;
You mean typedef int bool...
That (or its derivative) is what at least 69 places in the kernel do already. That is the whole point of discussion! The point is to unify it all into a kernel common place. I just suggested that using the compiler provided _Bool was better than using int.
Quoted 2 lines
And then happily use if(EXPR) and if(!EXPR) instead of if(EXPR == TRUE) or if(EXPR == FALSE). :-)
Obviously. No-one here is suggesting to use if (EXPR == TRUE) that is crazy. You would use if (EXPR) no matter what type you use. Technically only a boolean type should be used like that. The fact it works for an int is concidence because false = 0 and true = 1.
The point is 1) when assigning, you assign x = FALSE; rather than x = 0; which means nothing (it could be a counter you are initializing, no way to tell) and 2) for return values from functions and parameters to functions so it is easier to understand the semantics of the function.
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Randy.Dunlap
Quoted 6 lines · On Thu, 16 Mar 2006 16:01:30 +0000 Christoph Hellwig wrote:
Quoted 4 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.The patch also kills off a few private implementations of NULL.
NACK. Just kill them all and use 0/1
NACK to your NACK. (-;
Quoted 4 lines
Quoted 2 lines
nah, the only place that using symbolic names for true and false is a problem is when someone #defines or enums them bassackwards.
it makes the code longer and harder to read.
I could not disagree more. It does _exactly_ the opposite. It makes the code much easier to read but obviously you perceive it differently... I guess it is very much a matter of taste rather than anything else.
For me, black and white is much simpler than shades of grey and whilst you can emulate black and white with shades of grey it is still more effort to parse than true black and white.
Certainly I refuse to have my booleans (in the kernel or anywhere else) converted to 0 and 1 but I am all for unifying to a single boolean type across the kernel, so this patch gets a big ACK from me.
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Quoted 2 lines · Christoph Hellwig
it makes the code longer and harder to read. there's a reason the core code doesn't use it, and the periphal code should do the same.
Let see:
0 is an interger zero. It is not a null pointer.
1 is an interger one
NULL is an null pointer
We agree so far?
And you say:
0 is also false
1 is also true
But others say:
0 is not false, only false is false.
1 is not true, only true is true.
Thats more readable. No magic = 1; assignments or return 1; things.
Then we will have the case where a 1 is transformed to a true, and likewise a 0 to a false. But thats just normal type conversion.
I assume that when you are not used to see 'bool', 'true' and 'false' then they hurt the eye, but when used to it it looks natural.
Sam
Quoted 2 lines · Sam Ravnborg
I assume that when you are not used to see 'bool', 'true' and 'false' then they hurt the eye, but when used to it it looks natural.
Five words: kernel is written in C.
Not in Pascal. Not in C++. Not in Algol. "When used to (something non-idiomatic in C) it becomes natural" is not a valid argument.
Quoted 8 lines · On Thu, 16 Mar 2006 18:00:47 +0000 Al Viro wrote:
Quoted 2 lines · Sam Ravnborg
I assume that when you are not used to see 'bool', 'true' and 'false' then they hurt the eye, but when used to it it looks natural.
Five words: kernel is written in C.
Not in Pascal. Not in C++. Not in Algol. "When used to (something non-idiomatic in C) it becomes natural" is not a valid argument.
C (C99) now includes booleans. Are we stuck pre-C99?
---
~Randy
Quoted 6 lines · Randy.Dunlap
Quoted 4 lines · On Thu, 16 Mar 2006 18:00:47 +0000 Al Viro wrote:
Quoted 2 lines · Sam Ravnborg
I assume that when you are not used to see 'bool', 'true' and 'false' then they hurt the eye, but when used to it it looks natural.
Quoted 6 lines
Quoted 4 lines
Five words: kernel is written in C.
Not in Pascal. Not in C++. Not in Algol. "When used to (something non-idiomatic in C) it becomes natural" is not a valid argument.
C (C99) now includes booleans. Are we stuck pre-C99?
TRUE and FALSE are not those. Your point is...?
Quoted 7 lines · On Thu, 16 Mar 2006 18:49:46 +0000 Al Viro wrote:
Quoted 6 lines · Randy.Dunlap
Quoted 4 lines · On Thu, 16 Mar 2006 18:00:47 +0000 Al Viro wrote:
Quoted 2 lines · Sam Ravnborg
I assume that when you are not used to see 'bool', 'true' and 'false' then they hurt the eye, but when used to it it looks natural.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Five words: kernel is written in C.
Not in Pascal. Not in C++. Not in Algol. "When used to (something non-idiomatic in C) it becomes natural" is not a valid argument.
C (C99) now includes booleans. Are we stuck pre-C99?
TRUE and FALSE are not those. Your point is...?
Correct. So it would be better if they were spelled 'true' and 'false', as in the C99 spec?
---
~Randy
Quoted 5 lines · Al Viro
Quoted 2 lines · Sam Ravnborg
I assume that when you are not used to see 'bool', 'true' and 'false' then they hurt the eye, but when used to it it looks natural.
Five words: kernel is written in C.
Yep - and bool, true and false are part of 'C' - C99.
Quoted 3 lines
Not in Pascal. Not in C++. Not in Algol. "When used to (something non-idiomatic in C) it becomes natural" is not a valid argument.
The translation of idiomatic in my dictionary makes bool, true, false far more idiomatic in the C than NULL.
But history has thaugth us to accept NULL with screaming UPPERCASE where a null would be idiomatic C.
Sam
Quoted 2 lines · Randy.Dunlap
nah, the only place that using symbolic names for true and false is a problem is when someone #defines or enums them bassackwards.
Or goes off the deep end and does something like:
enum bool = {false, true, unknown};
http://thedailywtf.com/forums/47844/ShowPost.aspx
http://thedailywtf.com/forums/61792/ShowPost.aspx
Gaak. Unfortunately, they might someday try to write kernel code. ;)
Quoted 4 lines
Or goes off the deep end and does something like:
enum bool = {false, true, unknown};
Sounds like some of my AI code.
Quoted 2 lines · Randy.Dunlap
nah, the only place that using symbolic names for true and false is a problem is when someone #defines or enums them bassackwards.
Here's another danger associated with #define TRUE:
int x = ...;
if (x == TRUE)
do_something();A surprise happens if x is initialized to something other than 0 or 1. Looks like there maybe as many as a hundred instances of the above pattern in the kernel. Most of them seem safe, but I don't know whether they all are, and there are too many for me to check them all.
For instance, take a look at net/core/ethtool.c:ethtool_set_rx_csum() and drivers/net/ixgb/ixgb_ethtool.c:ixgb_set_rx_csum() and drivers/net/ixgb/ixgb_main.c:ixgb_configure_rx() for how it handles adapter->rx_csum to see one example that strikes me as dubious.
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.The patch also kills off a few private implementations of NULL.
NACK. Just kill them all and use 0/1
I'd say use var == 0 and var != 0 (or var and !var). While FALSE is obviously 0, TRUE isn't only 1.
Xav
Quoted 14 lines · On Thu, Mar 16, 2006 at 02:01:28AM -0800, [email protected] wrote:
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
In file included from
drivers/pci/hotplug/ibmphp_core.c:40:drivers/pci/hotplug/ibmphp.h:409:1: warning: "FALSE" redefined
In file included frominclude/acpi/acpi.h:55,
fromdrivers/pci/hotplug/pci_hotplug.h:187,
fromdrivers/pci/hotplug/ibmphp.h:33,
fromdrivers/pci/hotplug/ibmphp_core.c:40:include/acpi/actypes.h:336:1: warning: this is the location of the previous definition
Quoted 2 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.
NAK. Simply remove those and be done with that. It's bad style and we certainly don't need to propagate that lossage.
..oO[and no, #define BEGIN { is also not kernel.h fodder]
Quoted 16 lines · Al Viro
Quoted 14 lines · On Thu, Mar 16, 2006 at 02:01:28AM -0800, [email protected] wrote:
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
In file included from
drivers/pci/hotplug/ibmphp_core.c:40:drivers/pci/hotplug/ibmphp.h:409:1: warning: "FALSE" redefined
In file included frominclude/acpi/acpi.h:55,
fromdrivers/pci/hotplug/pci_hotplug.h:187,
fromdrivers/pci/hotplug/ibmphp.h:33,
fromdrivers/pci/hotplug/ibmphp_core.c:40:include/acpi/actypes.h:336:1: warning: this is the location of the previous definition
Quoted 5 lines
Quoted 2 lines
The patch implements TRUE and FALSE in
include/linux/kernel.hand removes all the private versions.NAK. Simply remove those and be done with that. It's bad style and we certainly don't need to propagate that lossage.
No, it is not bad style.
It is bad that the C design failed to distinguish between booleans and scalars. These are quite different concepts and it is a gruesome kludge to go and use a scalar when a boolean is what was intended.
There are readability (and hence maintainability) advantages in using boolean types for boolean variables.
Yes, the use of scalars in this manner is an (ancient, old-fashioned) C idiom. But it is one which was forced on us by shortcomings in the language. Times change. Just because something is idiomatic doesn't mean that it is either good or right. If C had had proper boolean support back in the old days then using scalars as booleans would be frowned upon.
C99 does have boolean support, so the proper thing to do is to start using it - implement stdbool.h, fix up fallout, start fixing subsystems. Given that, and as Greg has fixed up this particular build error I'll drop the patch.
(It's a shame that the compiler doesn't preperly enforce boolean typechecking, but sparse could do that).
Quoted 4 lines · On Thu, 16 Mar 2006 13:26:39 -0800 Andrew Morton <[email protected]> wrote:
C99 does have boolean support, so the proper thing to do is to start using it - implement
stdbool.h, fix up fallout, start fixing subsystems. Given that, and as Greg has fixed up this particular build error I'll drop the patch.
Isn't there a runtime cost converting all "non-false" values to a unique "true" (i.e. converting non-zero values to one) ? I mean:
bool res = strcmp(string, "whatever");
if(res)
something_else();
... will convert res to 0 or 1, which is totally useless except perhaps for comprehension (and again, not for Al Viro for example :)
Xav
Quoted 10 lines · Xavier Bestel
Quoted 4 lines · On Thu, 16 Mar 2006 13:26:39 -0800 Andrew Morton <[email protected]> wrote:
C99 does have boolean support, so the proper thing to do is to start using it - implement
stdbool.h, fix up fallout, start fixing subsystems. Given that, and as Greg has fixed up this particular build error I'll drop the patch.Isn't there a runtime cost converting all "non-false" values to a unique "true" (i.e. converting non-zero values to one) ?
Yes, there will be. If people do wrong things.
Quoted 5 lines
I mean:
bool res =
strcmp(string, "whatever");
if(res)something_else();
There's an implicit conversion from integer (-1, 0, 1) to boolean there. It _should_ require a typecast or, better,
bool res = (strcmp(...) != 0);
But it won't require that - the compiler will just accept it.. A new `gcc --implement-bools-properly' or perhaps sparse should warn about the above.
(Hopefully the compiler would have the brains to optimise it all away in this specific example).
But yeah, it's always possible to deoptimise your code.
Quoted 3 lines
Isn't there a runtime cost converting all "non-false" values to a unique "true" (i.e. converting non-zero values to one) ?
Somewhat. The answer is "yes, but depends on usage". If you just write
_Bool x = filthy_action(); if(x)
Then the compiler is smart enough to optimize 'x' away if it is not used somewhere else, therefore we do not pay a price for converting the return type of filthy_action (=int) to a _Bool.
The asm output for storing the result of filthy_action() [requires 'volatile int x' in this small example]
call strxcmp mov [ebp-4], eax
While making that a 'volatile _Bool x' makes it:
call strxcmp test eax, eax setnz al mov [ebp-1], al
Makes me prefer typedef int bool over _Bool.
Jan Engelhardt
Quoted 7 lines · Jan Engelhardt
Quoted 3 lines
Isn't there a runtime cost converting all "non-false" values to a unique "true" (i.e. converting non-zero values to one) ?
Somewhat. The answer is "yes, but depends on usage". If you just write
Quoted 6 lines
_Bool x = filthy_action(); if(x)Then the compiler is smart enough to optimize 'x' away if it is not used somewhere else, therefore we do not pay a price for converting the return type of
filthy_action(=int) to a_Bool.
Actually I find this behavior very good
Xavier
Quoted 6 lines · On Thu, Mar 16, 2006 at 02:01:28AM -0800, [email protected] wrote:
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
Quoted 7 lines
In file included from
drivers/pci/hotplug/ibmphp_core.c:40:drivers/pci/hotplug/ibmphp.h:409:1: warning: "FALSE" redefined
In file included frominclude/acpi/acpi.h:55,
fromdrivers/pci/hotplug/pci_hotplug.h:187,
fromdrivers/pci/hotplug/ibmphp.h:33,
fromdrivers/pci/hotplug/ibmphp_core.c:40:include/acpi/actypes.h:336:1: warning: this is the location of the previous definition
I have a patch in my queue that fixes this, in the ibmphp driver.
The acpi stuff should still be fixed though...
thanks,
greg k-h
Quoted 15 lines · Greg KH
Quoted 6 lines · On Thu, Mar 16, 2006 at 02:01:28AM -0800, [email protected] wrote:
From: Andrew Morton <[email protected]>
We have no less than 65 implementations of TRUE and FALSE in the tree, so the inevitable happened:
Quoted 7 lines
In file included from
drivers/pci/hotplug/ibmphp_core.c:40:drivers/pci/hotplug/ibmphp.h:409:1: warning: "FALSE" redefined
In file included frominclude/acpi/acpi.h:55,
fromdrivers/pci/hotplug/pci_hotplug.h:187,
fromdrivers/pci/hotplug/ibmphp.h:33,
fromdrivers/pci/hotplug/ibmphp_core.c:40:include/acpi/actypes.h:336:1: warning: this is the location of the previous definition
Quoted 1 line
I have a patch in my queue that fixes this, in the ibmphp driver.
Pushed out into my tree now, if you want to update your copy.
thanks,
greg k-h
Hi all
(and sorry Andrew for the double-mailing, hit the wrong button)
Quoted 8 lines · [email protected] wrote:
diff -puN
include/linux/kernel.h~consolidate-true-and-falseinclude/linux/kernel.hinclude/linux/kernel.h renamed from include/linux/kernel.h~consolidate-true-and-false +0
-0@@ -18,6 +18,13 @@extern const char linux_banner[];
include/linux/kernel.h line 30
Quoted 10 lines
include/linux/kernel.h renamed from include/linux/kernel.h~consolidate-true-and-false +7
-0+/* +* Give these a funny-looking definition to improve the chances of them +* clashing with other definitions of TRUE and FALSE, causing a cpp error +*/ +#define TRUE ((1)) +#define FALSE ((0)) +#define INT_MAX ((int)(~0U>>1))#define INT_MIN (-INT_MAX - 1)#define UINT_MAX (~0U)
Just an alternative implementation, letting "true" be true and "false" be false. Also making it similar to GCC's library.
---
include/linux/stdbool.h +15 -0
@@ -0,0 +1,15 @@ +/** +* Boolean handling +*/ +#ifndef _STDBOOL_H/* Same name as in GCC's include/stdbool.h */ +#define _STDBOOL_H + +typedef _Bool bool ; + +#define true ((0==0)) +#define false ((!true)) + +#define TRUE true +#define FALSE false + +#endif
include/linux/types.h +0 -0
@@ -3,6 +3,7 @@
#ifdef __KERNEL__
#include <linux/config.h>
+#include <linux/stdbool.h>
#define BITS_TO_LONGS(bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)