__FILE__,__LINE__等在哪儿定义的?

这些都是gcc的预定义宏(Predefined Macros),应该说这是各编程语言要求的,C++的就比C的稍微多一些。所以不论是gcc还是vc还是sun提供的cc等编译器都会有这些预定义宏 的。关于gcc的,大家可以到gcc官方网站上看到:http://gcc.gnu.org/onlinedocs/cpp/Predefined- Macros.html
__FILE__/__LINE__/__FUNCTION__/__DATE__/__TIME__/__STDC__ /__STDC_VERSION__/__STDC_HOSTED__/__cplusplus/__OBJC__/__ASSEMBLER__这些是 gcc的标准预定义宏(Standard Predefined Macros),对我们程序员来说都比较有用的,当然我之前的贴子里只用到了__FILE__/__LINE__/__FUNCTION__。
另外GNU还有一些公用的扩展出来的宏(Common Predefined Macros),比如:__GNUC__/__GNUC_MINOR__/__GNUC_PATCHLEVEL__/__VERSION__等关于gcc 版本的宏,另外还有__STRICT_ANSI__/__BASE_FILE__/__INCLUDE_LEVEL__等等一些宏,在gcc官方网站上你 可以看到有几十个宏定义(这还不包括那些与系统相关的宏),而且都有明确的说明,我觉得__BASE_FILE__这个宏也比较好,它代码的是你的程序的 main函数所在的那个源文件的名称。
具体到各系统,gcc官方网站明确说明你可以用cpp -dM命令来查看。
比如,对于上述程序例子,我输入了命令:
cpp -dM trace.c
结果得到如下几百个宏,其中大多与系统相关的,比如FILENAME_MAX指明文件明的最大长度:
#define _POSIX_LOGIN_NAME_MAX 9
#define __attribute__(xyz)
#define __restrict
#define SHRT_MAX 32767
#define _POSIX_THREAD_THREADS_MAX 64
#define __FDS_BITS(set) ((set)->__fds_bits)
#define __USER_LABEL_PREFIX__
#define NCARGS ARG_MAX
#define _IO_pos_t _G_fpos_t
#define _IO_DONT_CLOSE 0100000
#define __suseconds_t_defined
#define __USE_POSIX199506 1
#define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
#define _G_ssize_t __ssize_t
#define _IO_SHOWBASE 0200
#define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
#define __STRING(x) #x
#define CLK_TCK ((__clock_t) __sysconf (2))
#define _WCHAR_T_DEFINED_
#define __key_t_defined
#define __SIZE_TYPE__ unsigned int
#define clrbit(a, i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define _GCC_WCHAR_T
#define RTSIG_MAX 32
#define _IOS_OUTPUT 2
#define CLOCK_PROCESS_CPUTIME_ID 2
#define __isleap(year) ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
#define __volatile volatile
#define CLOCK_REALTIME 0
#define NOGROUP (-1)
#define _G_stat64 stat64
#define NFDBITS __NFDBITS
#define _IO_USER_BUF 1
#define _POSIX2_LINE_MAX 2048
#define __FDELT(d) ((d) / __NFDBITS)
#define _SYS_CDEFS_H 1
#define _STDIO_USES_IOSTREAM
#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
#define P_tmpdir "/tmp"
#define __LITTLE_ENDIAN 1234
#define _IO_UPPERCASE 01000
#define __USE_SVID 1
#define __WCHAR_T
#define __inline
#define setbit(a, i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define __USE_MISC 1
#define _LIMITS_H 1
#define _IO_size_t _G_size_t
#define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
#define _IO_off_t _G_off_t
#define PTHREAD_KEYS_MAX 1024
#define __fsfilcnt_t_defined
#define __clockid_t_defined 1
#define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
#define _G_size_t size_t
#define LINE_MAX _POSIX2_LINE_MAX
#define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
#define _POSIX_MQ_OPEN_MAX 8
#define __PTRDIFF_TYPE__ int
#define _IO_LEFT 02
#define _WCHAR_T
#define _GCONV_H 1
#define _G_HAVE_IO_FILE_OPEN 1
#define _BITS_TYPES_H 1
#define _POSIX_TZNAME_MAX 6
#define minor(dev) ((dev).__val[0] & 0xff)
#define MAX_CANON 255
#define _G_USING_THUNKS 1
#define _G_HAVE_LONG_DOUBLE_IO 1
#define SHRT_MIN (-32767-1)
#define _IO_wint_t _G_wint_t
#define _LIMITS_H___
#define MYFUNC_ONE_H
#define va_arg __builtin_va_arg
#define _POSIX_QLIMIT 1
#define TIMER_MAX 256
#define _IO_peekc_unlocked(_fp) ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end && __underflow (_fp) == EOF ? EOF : *(unsigned char *) (_fp)->_IO_read_ptr)
#define _G_HAVE_IO_GETLINE_INFO 1
#define _IO_UNITBUF 020000
#define _G_BUFSIZ 8192
#define _POSIX2_BC_DIM_MAX 2048
#define _ENDIAN_H 1
#define BIG_ENDIAN __BIG_ENDIAN
#define AIO_PRIO_DELTA_MAX 20
#define _G_NEED_STDARG_H 1
#define CHILD_MAX 999
#define RE_DUP_MAX (0x7fff)
#define __flexarr [1]
#define __ptrvalue
#define _POSIX_AIO_MAX 1
#define __HAVE_BUILTIN_SETJMP__ 1
#define __stub_fexecve
#define __BIG_ENDIAN 4321
#define SEEK_SET 0
#define __i386 1
#define SSIZE_MAX INT_MAX
#define __wchar_t__
#define __gid_t_defined
#define _POSIX_OPEN_MAX 16
#define _WCHAR_T_
#define __need_clockid_t
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#define __va_list__
#define __USE_POSIX 1
#define _T_WCHAR
#define _LIBC_LIMITS_H_ 1
#define __stub_sigreturn
#define _IO_cleanup_region_end(_Doit)
#define _IO_ftrylockfile(_fp)
#define PATH_MAX 4095
#define _POSIX_SOURCE 1
#define _IO_uid_t _G_uid_t
#define _IO_MAGIC 0xFBAD0000
#define PDP_ENDIAN __PDP_ENDIAN
#define powerof2(x) ((((x)-1)&(x))==0)
#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
#define _POSIX_STREAM_MAX 8
#define _POSIX2_COLL_WEIGHTS_MAX 2
#define _POSIX_FD_SETSIZE _POSIX_OPEN_MAX
#define __stub_chflags
#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
#define __GLIBC_MINOR__ 2
#define _IO_NO_READS 4
#define FILENAME_MAX 4095
#define __u_char_defined
#define DEV_BSIZE 512
#define _IO_getwc_unlocked(_fp) ((_fp)->_wide_data->_IO_read_ptr >= (_fp)->_wide_data->_IO_read_end ? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
#define _ANSI_STDARG_H_
#define __ELF__ 1
#define _POSIX2_EXPR_NEST_MAX 32
#define _IOS_BIN 128
#define __size_t__
#define MAX(a, b) (((a)>(b))?(a):(b))
#define _SIGSET_H_types 1
#define __stub_fattach
#define __NFDBITS (8 * sizeof (__fd_mask))
#define __restrict_arr
#define __ptr_t void *
#define PIPE_BUF 4096
#define __daddr_t_defined
#define _BSD_SOURCE 1
#define _IO_putwc_unlocked(_wch, _fp) ((_fp)->_wide_data->_IO_write_ptr >= (_fp)->_wide_data->_IO_write_end ? __woverflow (_fp, _wch) : (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define __unbounded
#define _IO_INTERNAL 010
#define _TIME_H 1
#define __WCHAR_TYPE__ long int
#define _POSIX_UIO_MAXIOV 16
#define _PTHREAD_DESCR_DEFINED
#define TIMER_ABSTIME 1
#define __KERNEL_STRICT_NAMES
#define __SIZE_T
#define __attribute_format_arg__(x)
#define _IO_fpos_t _G_fpos_t
#define __NO_INLINE__ 1
#define _SIZE_T_DEFINED
#define _IOLBF 1
#define _IO_BUFSIZ _G_BUFSIZ
#define __time_t_defined 1
#define _IO_funlockfile(_fp)
#define __GNUC_VA_LIST
#define NULL ((void *)0)
#define NBBY CHAR_BIT
#define L_ctermid 9
#define _IO_PENDING_OUTPUT_COUNT(_fp) ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
#define _POSIX_SEM_NSEMS_MAX 256
#define __va_copy(d, s) __builtin_va_copy((d),(s))
#define ULONG_MAX (LONG_MAX * 2UL + 1)
#define _G_pid_t __pid_t
#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
#define _VA_LIST
#define _IO_ssize_t _G_ssize_t
#define _POSIX_NGROUPS_MAX 0
#define _POSIX_MAX_INPUT 255
#define __USE_BSD 1
#define L_cuserid 9
#define __stub___kernel_tanl
#define NOFILE 256
#define _IO_IS_FILEBUF 0x2000
#define __WORDSIZE 32
#define __int8_t_defined
#define CANBSIZ MAX_CANON
#define EXEC_PAGESIZE 4096
#define _IO_LINE_BUF 0x200
#define _IO_STDIO_H
#define _SYS_TYPES_H 1
#define _G_OPEN64 __open64
#define _T_SIZE
#define __WINT_TYPE__ unsigned int
#define MIN(a, b) (((a)<(b))?(a):(b))
#define __timer_t_defined 1
#define _LINUX_PARAM_H
#define _POSIX_SEM_VALUE_MAX 32767
#define _G_IO_IO_FILE_VERSION 0x20001
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
#define _PARAMS(protos) __P(protos)
#define _POSIX_ARG_MAX 4096
#define __uid_t_defined
#define __stub_posix_fadvise64
#define __mbstate_t_defined 1
#define _POSIX2_BC_STRING_MAX 1000
#define ARG_MAX 131072
#define _SIZET_
#define __GNU_LIBRARY__ 6
#define _SYS_SELECT_H 1
#define _BITS_POSIX1_LIM_H 1
#define _GCC_SIZE_T
#define __clock_t_defined 1
#define __GLIBC_PREREQ(maj, min) ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
#define _G_LSEEK64 __lseek64
#define LONG_MAX __LONG_MAX__
#define __PMT(args) args
#define EOF (-1)
#define MAXPATHLEN PATH_MAX
#define _IO_SHOWPOINT 0400
#define va_end __builtin_va_end
#define _IO_CURRENTLY_PUTTING 0x800
#define DUMP_H
#define __LONG_LONG_PAIR(HI, LO) LO, HI
#define NAME_MAX 255
#define _OLD_STDIO_MAGIC 0xFABC0000
#define _POSIX_AIO_LISTIO_MAX 2
#define _G_VTABLE_LABEL_PREFIX_ID __vt_
#define _IO_flockfile(_fp)
#define _G_HAVE_ST_BLKSIZE defined (_STATBUF_ST_BLKSIZE)
#define putc(_ch, _fp) _IO_putc (_ch, _fp)
#define _IO_FIXED 010000
#define _POSIX_THREAD_KEYS_MAX 128
#define _IO_off64_t _G_off64_t
#define __PDP_ENDIAN 3412
#define _IO_va_list __gnuc_va_list
#define __LONG_MAX__ 2147483647L
#define _BITS_WCHAR_H 1
#define _IO_SHOWPOS 02000
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define _WCHAR_T_H
#define _IOS_ATEND 4
#define stderr stderr
#define _IO_TIED_PUT_GET 0x400
#define __tune_i386__ 1
#define _POSIX2_BC_BASE_MAX 99
#define __unix 1
#define unix 1
#define stdout stdout
#define __defined_schedparam 1
#define _POSIX_TIMER_MAX 32
#define __P(args) args
#define _STDIO_H 1
#define __STDC_IEC_559__ 1
#define BYTE_ORDER __BYTE_ORDER
#define __nlink_t_defined
#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
#define _IO_NO_WRITES 8
#define __sigset_t_defined
#define __UNKNOWN_10646_CHAR ((wchar_t) 0xfffd)
#define __WCHAR_MAX (2147483647l)
#define _IONBF 2
#define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
#define _IO_SKIPWS 01
#define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
#define _STDARG_H
#define major(dev) (((dev).__val[0] >> 8) & 0xff)
#define _G_HAVE_MMAP 1
#define _POSIX_SSIZE_MAX 32767
#define MAX_INPUT 255
#define PTHREAD_STACK_MIN 16384
#define __extension__
#define LONG_MIN (-LONG_MAX-1)
#define _G_off_t __off_t
#define __stub_sstk
#define _IO_fpos64_t _G_fpos64_t
#define isclr(a, i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#define __FILE_defined 1
#define _IO_MAGIC_MASK 0xFFFF0000
#define howmany(x, y) (((x)+((y)-1))/(y))
#define _IO_iconv_t _G_iconv_t
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _IO_HEX 0100
#define __signed signed
#define GLOBAL_H
#define _SYS_SYSMACROS_H 1
#define __pid_t_defined
#define _SIZE_T
#define FD_SETSIZE __FD_SETSIZE
#define _IO_cleanup_region_start(_fct, _fp)
#define _POSIX2_BC_SCALE_MAX 99
#define _VA_LIST_T_H
#define _IOS_TRUNC 16
#define __stub___kernel_cosl
#define getc(_fp) _IO_getc (_fp)
#define _IO_UNBUFFERED 2
#define _ASMi386_PARAM_H
#define _IO_DELETE_DONT_CLOSE 0x40
#define makedev(major, minor) { ((((unsigned int) (major)) << 8) | ((unsigned int) (minor))), 0 }
#define __BIT_TYPES_DEFINED__ 1
#define FOPEN_MAX 16
#define __attribute_malloc__
#define _IO_RIGHT 04
#define BC_BASE_MAX _POSIX2_BC_BASE_MAX
#define BC_DIM_MAX _POSIX2_BC_DIM_MAX
#define _IO_IS_APPENDING 0x1000
#define __REGISTER_PREFIX__
#define __mode_t_defined
#define _WINT_T
#define _BITS_POSIX2_LIM_H 1
#define __attribute_pure__
#define __HAVE_COLUMN
#define ___int_size_t_h
#define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
#define _IO_pid_t _G_pid_t
#define _T_SIZE_
#define _POSIX_C_SOURCE 199506L
#define _POSIX_PATH_MAX 256
#define __STDC_IEC_559_COMPLEX__ 1
#define __stub___kernel_sinl
#define __id_t_defined
#define _G_HAVE_PRINTF_FP 1
#define EXPR_NEST_MAX _POSIX2_EXPR_NEST_MAX
#define _G_HAVE_BOOL 1
#define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS))
#define stdin stdin
#define __stub_stty
#define _G_HAVE_SYS_WAIT 1
#define SCHAR_MAX 127
#define __ssize_t_defined
#define _IOS_NOCREATE 32
#define UCHAR_MAX 255
#define _POSIX2_RE_DUP_MAX 255
#define __STDC_ISO_10646__ 200009L
#define _POSIX_MQ_PRIO_MAX 32
#define _G_NAMES_HAVE_UNDERSCORE 0
#define _IO_DEC 020
#define _G_VTABLE_LABEL_HAS_LENGTH 1
#define _SIZE_T_
#define _IO_EOF_SEEN 0x10
#define va_copy(d, s) __builtin_va_copy((d),(s))
#define __linux 1
#define _SIZE_T_DEFINED_
#define _IO_putc_unlocked(_ch, _fp) (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) ? __overflow (_fp, (unsigned char) (_ch)) : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
#define _STRUCT_TIMEVAL 1
#define _G_va_list __gnuc_va_list
#define _POSIX_DELAYTIMER_MAX 32
#define _MACH_MACHLIMITS_H_
#define _G_ARGS(ARGLIST) ARGLIST
#define MAXSYMLINKS 20
#define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
#define _POSIX_SIGQUEUE_MAX 32
#define _POSIX_PIPE_BUF 512
#define __GLIBC__ 2
#define i386 1
#define __BYTE_ORDER __LITTLE_ENDIAN
#define __const const
#define _SVID_SOURCE 1
#define __END_DECLS
#define CHAR_MAX 127
#define _IOFBF 0
#define _G_HAVE_ATEXIT 1
#define __GNUC_PREREQ(maj, min) 0
#define MYFUNC_TWO_H
#define _IO_LINKED 0x80
#define _VA_LIST_DEFINED
#define _IO_OCT 040
#define _SYS_SIZE_T_H
#define _IO_getc_unlocked(_fp) ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++)
#define __linux__ 1
#define __USE_ANSI 1
#define __CONCAT(x, y) x ## y
#define __VERSION__ "2.96 20000731 (Red Hat Linux 7.1 2.96-98)"
#define _BITS_PTHREADTYPES_H 1
#define __FD_ZERO(set) do { unsigned int __i; fd_set *__arr = (set); for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) __FDS_BITS (__arr)[__i] = 0; } while (0)
#define __USE_POSIX2 1
#define NGROUPS 32
#define __BEGIN_DECLS
#define __blkcnt_t_defined
#define NGROUPS_MAX 32
#define __stub_fchflags
#define __size_t
#define _G_wchar_t wchar_t
#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
#define MAXHOSTNAMELEN 64
#define _G_FSTAT64(fd, buf) __fxstat64 (_STAT_VER, fd, buf)
#define _IOS_APPEND 8
#define _IO_BAD_SEEN 0x4000
#define SCHAR_MIN (-128)
#define __off_t_defined
#define L_tmpnam 20
#define _T_WCHAR_
#define __ino_t_defined
#define INT_MAX __INT_MAX__
#define BC_STRING_MAX _POSIX2_BC_STRING_MAX
#define __USE_POSIX199309 1
#define MB_LEN_MAX 16
#define CHAR_BIT 8
#define __FD_SETSIZE 1024
#define __attribute_format_strfmon__(a, b)
#define BUFSIZ _IO_BUFSIZ
#define _POSIX_RTSIG_MAX 8
#define _IO_BOOLALPHA 0200000
#define _LINUX_LIMITS_H
#define _IO_file_flags _flags
#define _G_VTABLE_LABEL_PREFIX "__vt_"
#define __stub_revoke
#define _BITS_TIME_H 1
#define __INT_MAX__ 2147483647
#define PTHREAD_THREADS_MAX 1024
#define _G_off64_t __off64_t
#define ___int_wchar_t_h
#define _IO_USER_LOCK 0x8000
#define __fsblkcnt_t_defined
#define _IO_UNIFIED_JUMPTABLES 1
#define __stub_posix_fadvise
#define _VA_LIST_
#define _POSIX_HIWAT _POSIX_PIPE_BUF
#define va_start(v, l) __builtin_stdarg_start((v),l)
#define _IOS_NOREPLACE 64
#define __dev_t_defined
#define _POSIX_LINK_MAX 8
#define _IOS_INPUT 1
#define UINT_MAX (INT_MAX * 2U + 1)
#define HZ 100
#define __timespec_defined 1
#define _FEATURES_H 1
#define CHAR_MIN (-128)
#define __stub_gtty
#define _POSIX_TTY_NAME_MAX 9
#define __i386__ 1
#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
#define __stub_setlogin
#define SEEK_CUR 1
#define __INT_WCHAR_T_H
#define _IO_IN_BACKUP 0x100
#define linux 1
#define _POSIX_NAME_MAX 14
#define dump(fp, x...)
#define __WCHAR_MIN (-2147483647l - 1l)
#define _IO_ERR_SEEN 0x20
#define CLOCKS_PER_SEC 1000000l
#define TMP_MAX 238328
#define USHRT_MAX 65535
#define _POSIX_CLOCKRES_MIN 20000000
#define _POSIX_MAX_CANON 255
#define _G_uid_t __uid_t
#define _G_wint_t wint_t
#define __THROW
#define _WCHAR_T_DEFINED
#define INT_MIN (-INT_MAX-1)
#define _SYS_PARAM_H 1
#define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
#define _IO_SCIENTIFIC 04000
#define __FLOAT_WORD_ORDER __BYTE_ORDER
#define ____FILE_defined 1
#define __unix__ 1
#define COLL_WEIGHTS_MAX 255
#define CHARCLASS_NAME_MAX 2048
#define _BSD_SIZE_T_
#define _GCC_LIMITS_H_
#define __bounded
#define __long_double_t long double
#define SEEK_END 2
#define _POSIX_CHILD_MAX 6
#define _G_HAVE_SYS_CDEFS 1
#define __stub_fdetach
#define _IO_STDIO 040000
#define _G_config_h 1
#define CLOCK_THREAD_CPUTIME_ID 3
#define BC_SCALE_MAX _POSIX2_BC_SCALE_MAX
#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT

 

 

不过最关键的是明白每个宏的意义。

你可能感兴趣的:(thread,IO,File,gcc,FP,destructor)