VirtualBox

source: vbox/trunk/include/iprt/cdefs.h@ 4011

Last change on this file since 4011 was 3642, checked in by vboxsync, 17 years ago

darn.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.9 KB
Line 
1/** @file
2 * innotek Portable Runtime - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#ifndef ___iprt_cdefs_h
22#define ___iprt_cdefs_h
23
24
25/** @defgroup grp_rt_cdefs innotek Portable Runtime Common Definitions and Macros
26 * @{
27 */
28
29/*
30 * Include sys/cdefs.h if present, if not define the stuff we need.
31 */
32#ifdef HAVE_SYS_CDEFS_H
33# if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
34# error "oops"
35# endif
36# include <sys/cdefs.h>
37#else
38
39 /** @def __BEGIN_DECLS
40 * Used to start a block of function declarations which are shared
41 * between C and C++ program.
42 */
43
44 /** @def __END_DECLS
45 * Used to end a block of function declarations which are shared
46 * between C and C++ program.
47 */
48
49 #if defined(__cplusplus)
50 # define __BEGIN_DECLS extern "C" {
51 # define __END_DECLS }
52 #else
53 # define __BEGIN_DECLS
54 # define __END_DECLS
55 #endif
56
57#endif
58
59
60/*
61 * Shut up DOXYGEN warnings and guide it properly thru the code.
62 */
63#ifdef __DOXYGEN__
64#define __AMD64__
65#define __X86__
66#define RT_ARCH_AMD64
67#define RT_ARCH_X86
68#define IN_RING0
69#define IN_RING3
70#define IN_GC
71#define IN_RT_GC
72#define IN_RT_R0
73#define IN_RT_R3
74#define RT_STRICT
75#define Breakpoint
76#define RT_NO_DEPRECATED_MACROS
77#define ARCH_BITS
78#define HC_ARCH_BITS
79#define R3_ARCH_BITS
80#define R0_ARCH_BITS
81#define GC_ARCH_BITS
82#endif /* __DOXYGEN__ */
83
84/* A temporary hack. */
85#ifndef RT_OS_LINUX
86# ifdef __LINUX__
87# define RT_OS_LINUX
88# warning "__LINUX__ without RT_OS_LINUX!"
89# endif
90#endif
91
92/** @def RT_ARCH_X86
93 * Indicates that we're compiling for the X86 architecture.
94 */
95
96/** @def RT_ARCH_AMD64
97 * Indicates that we're compiling for the AMD64 architecture.
98 */
99#if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
100# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
101# define RT_ARCH_AMD64
102# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
103# define RT_ARCH_X86
104# else /* PORTME: append test for new archs. */
105# error "Check what predefined stuff your compiler uses to indicate architecture."
106# endif
107#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
108# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
109#endif
110
111
112/** @def __X86__
113 * Indicates that we're compiling for the X86 architecture.
114 * @deprecated
115 */
116
117/** @def __AMD64__
118 * Indicates that we're compiling for the AMD64 architecture.
119 * @deprecated
120 */
121#if !defined(__X86__) && !defined(__AMD64__)
122# if defined(RT_ARCH_AMD64)
123# define __AMD64__
124# elif defined(RT_ARCH_X86)
125# define __X86__
126# else
127# error "Check what predefined stuff your compiler uses to indicate architecture."
128# endif
129#elif defined(__X86__) && defined(__AMD64__)
130# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
131#elif defined(__X86__) && !defined(RT_ARCH_X86)
132# error "Both __X86__ without RT_ARCH_X86!"
133#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
134# error "Both __AMD64__ without RT_ARCH_AMD64!"
135#endif
136
137/** @def IN_RING0
138 * Used to indicate that we're compiling code which is running
139 * in Ring-0 Host Context.
140 */
141
142/** @def IN_RING3
143 * Used to indicate that we're compiling code which is running
144 * in Ring-3 Host Context.
145 */
146
147/** @def IN_GC
148 * Used to indicate that we're compiling code which is running
149 * in Guest Context (implies R0).
150 */
151#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_GC)
152# error "You must defined which context the compiled code should run in; IN_RING3, IN_RING0 or IN_GC"
153#endif
154#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_GC)) ) \
155 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_GC)) ) \
156 || (defined(IN_GC) && (defined(IN_RING3) || defined(IN_RING0)) )
157# error "Only one of the IN_RING3, IN_RING0, IN_GC defines should be defined."
158#endif
159
160
161/** @def ARCH_BITS
162 * Defines the bit count of the current context.
163 */
164#ifndef ARCH_BITS
165# if defined(RT_ARCH_AMD64)
166# define ARCH_BITS 64
167# else
168# define ARCH_BITS 32
169# endif
170#endif
171
172/** @def HC_ARCH_BITS
173 * Defines the host architechture bit count.
174 */
175#ifndef HC_ARCH_BITS
176# ifndef IN_GC
177# define HC_ARCH_BITS ARCH_BITS
178# else
179# define HC_ARCH_BITS 32
180# endif
181#endif
182
183/** @def R3_ARCH_BITS
184 * Defines the host ring-3 architechture bit count.
185 */
186#ifndef R3_ARCH_BITS
187# ifdef IN_RING3
188# define R3_ARCH_BITS ARCH_BITS
189# else
190# define R3_ARCH_BITS HC_ARCH_BITS
191# endif
192#endif
193
194/** @def R0_ARCH_BITS
195 * Defines the host ring-0 architechture bit count.
196 */
197#ifndef R0_ARCH_BITS
198# ifdef IN_RING0
199# define R0_ARCH_BITS ARCH_BITS
200# else
201# define R0_ARCH_BITS HC_ARCH_BITS
202# endif
203#endif
204
205/** @def GC_ARCH_BITS
206 * Defines the guest architechture bit count.
207 */
208#ifndef GC_ARCH_BITS
209# ifdef IN_GC
210# define GC_ARCH_BITS ARCH_BITS
211# else
212# define GC_ARCH_BITS 32
213# endif
214#endif
215
216
217/** @def CTXTYPE
218 * Declare a type differently in GC, R3 and R0.
219 *
220 * @param GCType The GC type.
221 * @param R3Type The R3 type.
222 * @param R0Type The R0 type.
223 * @remark For pointers used only in one context use GCPTRTYPE(), HCPTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
224 */
225#ifdef IN_GC
226# define CTXTYPE(GCType, R3Type, R0Type) GCType
227#elif defined(IN_RING3)
228# define CTXTYPE(GCType, R3Type, R0Type) R3Type
229#else
230# define CTXTYPE(GCType, R3Type, R0Type) R0Type
231#endif
232
233/** @def GCTYPE
234 * Declare a type differently in GC and HC.
235 *
236 * @param GCType The GC type.
237 * @param HCType The HC type.
238 * @remark For pointers used only in one context use GCPTRTYPE(), HCPTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
239 */
240#define GCTYPE(GCType, HCType) CTXTYPE(GCType, HCType, HCType)
241
242/** @def GCPTRTYPE
243 * Declare a pointer which is used in GC but appears in structure(s) used by
244 * both HC and GC. The main purpose is to make sure structures have the same
245 * size when built for different architectures.
246 *
247 * @param GCType The GC type.
248 */
249#define GCPTRTYPE(GCType) CTXTYPE(GCType, RTGCPTR, RTGCPTR)
250
251/** @def HCPTRTYPE
252 * Declare a pointer which is used in HC but appears in structure(s) used by
253 * both HC and GC. The main purpose is to make sure structures have the same
254 * size when built for different architectures.
255 *
256 * @param HCType The HC type.
257 */
258#define HCPTRTYPE(HCType) CTXTYPE(RTHCPTR, HCType, HCType)
259
260/** @def R3PTRTYPE
261 * Declare a pointer which is used in R3 but appears in structure(s) used by
262 * both HC and GC. The main purpose is to make sure structures have the same
263 * size when built for different architectures.
264 *
265 * @param R3Type The R3 type.
266 */
267#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
268
269/** @def R0PTRTYPE
270 * Declare a pointer which is used in R0 but appears in structure(s) used by
271 * both HC and GC. The main purpose is to make sure structures have the same
272 * size when built for different architectures.
273 *
274 * @param R0Type The R0 type.
275 */
276#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
277
278/** @def CTXSUFF
279 * Adds the suffix of the current context to the passed in
280 * identifier name. The suffix is HC or GC.
281 *
282 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
283 * @param var Identifier name.
284 */
285/** @def OTHERCTXSUFF
286 * Adds the suffix of the other context to the passed in
287 * identifier name. The suffix is HC or GC.
288 *
289 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
290 * @param var Identifier name.
291 */
292#ifdef IN_GC
293# define CTXSUFF(var) var##GC
294# define OTHERCTXSUFF(var) var##HC
295#else
296# define CTXSUFF(var) var##HC
297# define OTHERCTXSUFF(var) var##GC
298#endif
299
300/** @def CTXALLSUFF
301 * Adds the suffix of the current context to the passed in
302 * identifier name. The suffix is R3, R0 or GC.
303 *
304 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
305 * @param var Identifier name.
306 */
307#ifdef IN_GC
308# define CTXALLSUFF(var) var##GC
309#elif defined(IN_RING0)
310# define CTXALLSUFF(var) var##R0
311#else
312# define CTXALLSUFF(var) var##R3
313#endif
314
315/** @def CTXMID
316 * Adds the current context as a middle name of an identifier name
317 * The middle name is HC or GC.
318 *
319 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
320 * @param first First name.
321 * @param last Surname.
322 */
323/** @def OTHERCTXMID
324 * Adds the other context as a middle name of an identifier name
325 * The middle name is HC or GC.
326 *
327 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
328 * @param first First name.
329 * @param last Surname.
330 */
331#ifdef IN_GC
332# define CTXMID(first, last) first##GC##last
333# define OTHERCTXMID(first, last) first##HC##last
334#else
335# define CTXMID(first, last) first##HC##last
336# define OTHERCTXMID(first, last) first##GC##last
337#endif
338
339/** @def CTXALLMID
340 * Adds the current context as a middle name of an identifier name
341 * The middle name is R3, R0 or GC.
342 *
343 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
344 * @param first First name.
345 * @param last Surname.
346 */
347#ifdef IN_GC
348# define CTXALLMID(first, last) first##GC##last
349#elif defined(IN_RING0)
350# define CTXALLMID(first, last) first##R0##last
351#else
352# define CTXALLMID(first, last) first##R3##last
353#endif
354
355
356/** @def R3STRING
357 * A macro which in GC and R0 will return a dummy string while in R3 it will return
358 * the parameter.
359 *
360 * This is typically used to wrap description strings in structures shared
361 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
362 *
363 * @param pR3String The R3 string. Only referenced in R3.
364 * @see R0STRING and GCSTRING
365 */
366#ifdef IN_RING3
367# define R3STRING(pR3String) (pR3String)
368#else
369# define R3STRING(pR3String) ("<R3_STRING>")
370#endif
371
372/** @def R0STRING
373 * A macro which in GC and R3 will return a dummy string while in R0 it will return
374 * the parameter.
375 *
376 * This is typically used to wrap description strings in structures shared
377 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
378 *
379 * @param pR0String The R0 string. Only referenced in R0.
380 * @see R3STRING and GCSTRING
381 */
382#ifdef IN_RING0
383# define R0STRING(pR0String) (pR0String)
384#else
385# define R0STRING(pR0String) ("<R0_STRING>")
386#endif
387
388/** @def GCSTRING
389 * A macro which in R3 and R0 will return a dummy string while in GC it will return
390 * the parameter.
391 *
392 * This is typically used to wrap description strings in structures shared
393 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_GC mess.
394 *
395 * @param pR0String The GC string. Only referenced in GC.
396 * @see R3STRING, R0STRING
397 */
398#ifdef IN_GC
399# define GCSTRING(pR0String) (pGCString)
400#else
401# define GCSTRING(pR0String) ("<GC_STRING>")
402#endif
403
404/** @def HCSTRING
405 * Macro which in GC will return a dummy string while in HC will return
406 * the parameter.
407 *
408 * This is typically used to wrap description strings in structures shared
409 * between HC and GC. The intention is to avoid the \#ifdef IN_GC kludge.
410 *
411 * @param pHCString The HC string. Only referenced in HC.
412 * @deprecated Use R3STRING or R0STRING instead.
413 */
414#ifdef IN_GC
415# define HCSTRING(pHCString) ("<HC_STRING>")
416#else
417# define HCSTRING(pHCString) (pHCString)
418#endif
419
420
421/** @def RTCALL
422 * The standard calling convention for the Runtime interfaces.
423 */
424#ifdef _MSC_VER
425# define RTCALL __cdecl
426#elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
427# define RTCALL __attribute__((cdecl,regparm(0)))
428#else
429# define RTCALL
430#endif
431
432/** @def DECLEXPORT
433 * How to declare an exported function.
434 * @param type The return type of the function declaration.
435 */
436#if defined(_MSC_VER) || defined(RT_OS_OS2)
437# define DECLEXPORT(type) __declspec(dllexport) type
438#else
439# ifdef VBOX_HAVE_VISIBILITY_HIDDEN
440# define DECLEXPORT(type) __attribute__((visibility("default"))) type
441# else
442# define DECLEXPORT(type) type
443# endif
444#endif
445
446/** @def DECLIMPORT
447 * How to declare an imported function.
448 * @param type The return type of the function declaration.
449 */
450#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
451# define DECLIMPORT(type) __declspec(dllimport) type
452#else
453# define DECLIMPORT(type) type
454#endif
455
456/** @def DECLASM
457 * How to declare an internal assembly function.
458 * @param type The return type of the function declaration.
459 */
460#ifdef __cplusplus
461# ifdef _MSC_VER
462# define DECLASM(type) extern "C" type __cdecl
463# else
464# define DECLASM(type) extern "C" type
465# endif
466#else
467# ifdef _MSC_VER
468# define DECLASM(type) type __cdecl
469# else
470# define DECLASM(type) type
471# endif
472#endif
473
474/** @def DECLASMTYPE
475 * How to declare an internal assembly function type.
476 * @param type The return type of the function.
477 */
478#ifdef _MSC_VER
479# define DECLASMTYPE(type) type __cdecl
480#else
481# define DECLASMTYPE(type) type
482#endif
483
484/** @def DECLCALLBACK
485 * How to declare an call back function type.
486 * @param type The return type of the function declaration.
487 */
488#define DECLCALLBACK(type) type RTCALL
489
490/** @def DECLCALLBACKPTR
491 * How to declare an call back function pointer.
492 * @param type The return type of the function declaration.
493 * @param name The name of the variable member.
494 */
495#define DECLCALLBACKPTR(type, name) type (RTCALL * name)
496
497/** @def DECLCALLBACKMEMBER
498 * How to declare an call back function pointer member.
499 * @param type The return type of the function declaration.
500 * @param name The name of the struct/union/class member.
501 */
502#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
503
504/** @def DECLR3CALLBACKMEMBER
505 * How to declare an call back function pointer member - R3 Ptr.
506 * @param type The return type of the function declaration.
507 * @param name The name of the struct/union/class member.
508 * @param args The argument list enclosed in parentheses.
509 */
510#ifdef IN_RING3
511# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
512#else
513# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
514#endif
515
516/** @def DECLGCCALLBACKMEMBER
517 * How to declare an call back function pointer member - GC Ptr.
518 * @param type The return type of the function declaration.
519 * @param name The name of the struct/union/class member.
520 * @param args The argument list enclosed in parentheses.
521 */
522#ifdef IN_GC
523# define DECLGCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
524#else
525# define DECLGCCALLBACKMEMBER(type, name, args) RTGCPTR name
526#endif
527
528/** @def DECLR0CALLBACKMEMBER
529 * How to declare an call back function pointer member - R0 Ptr.
530 * @param type The return type of the function declaration.
531 * @param name The name of the struct/union/class member.
532 * @param args The argument list enclosed in parentheses.
533 */
534#ifdef IN_RING0
535# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
536#else
537# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
538#endif
539
540/** @def DECLINLINE
541 * How to declare a function as inline.
542 * @param type The return type of the function declaration.
543 */
544#ifdef __GNUC__
545# define DECLINLINE(type) static inline type
546#elif defined(__cplusplus)
547# define DECLINLINE(type) inline type
548#elif defined(_MSC_VER)
549# define DECLINLINE(type) _inline type
550#elif defined(__IBMC__)
551# define DECLINLINE(type) _Inline type
552#else
553# define DECLINLINE(type) inline type
554#endif
555
556
557/** @def IN_RT_R0
558 * Used to indicate whether we're inside the same link module as
559 * the HC Ring-0 Runtime Library.
560 */
561/** @def RTR0DECL(type)
562 * Runtime Library HC Ring-0 export or import declaration.
563 * @param type The return type of the function declaration.
564 */
565#ifdef IN_RT_R0
566# define RTR0DECL(type) DECLEXPORT(type) RTCALL
567#else
568# define RTR0DECL(type) DECLIMPORT(type) RTCALL
569#endif
570
571/** @def IN_RT_R3
572 * Used to indicate whether we're inside the same link module as
573 * the HC Ring-3 Runtime Library.
574 */
575/** @def RTR3DECL(type)
576 * Runtime Library HC Ring-3 export or import declaration.
577 * @param type The return type of the function declaration.
578 */
579#ifdef IN_RT_R3
580# define RTR3DECL(type) DECLEXPORT(type) RTCALL
581#else
582# define RTR3DECL(type) DECLIMPORT(type) RTCALL
583#endif
584
585/** @def IN_RT_GC
586 * Used to indicate whether we're inside the same link module as
587 * the GC Runtime Library.
588 */
589/** @def RTGCDECL(type)
590 * Runtime Library HC Ring-3 export or import declaration.
591 * @param type The return type of the function declaration.
592 */
593#ifdef IN_RT_GC
594# define RTGCDECL(type) DECLEXPORT(type) RTCALL
595#else
596# define RTGCDECL(type) DECLIMPORT(type) RTCALL
597#endif
598
599/** @def RTDECL(type)
600 * Runtime Library export or import declaration.
601 * Functions declared using this macro exists in all contexts.
602 * @param type The return type of the function declaration.
603 */
604#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
605# define RTDECL(type) DECLEXPORT(type) RTCALL
606#else
607# define RTDECL(type) DECLIMPORT(type) RTCALL
608#endif
609
610/** @def RTDATADECL(type)
611 * Runtime Library export or import declaration.
612 * Data declared using this macro exists in all contexts.
613 * @param type The return type of the function declaration.
614 */
615#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
616# define RTDATADECL(type) DECLEXPORT(type)
617#else
618# define RTDATADECL(type) DECLIMPORT(type)
619#endif
620
621
622/** @def RT_NOCRT
623 * Symbol name wrapper for the No-CRT bits.
624 *
625 * In order to coexist in the same process as other CRTs, we need to
626 * decorate the symbols such that they don't conflict the ones in the
627 * other CRTs. The result of such conflicts / duplicate symbols can
628 * confuse the dynamic loader on unix like systems.
629 *
630 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
631 */
632/** @def RT_NOCRT_STR
633 * Same as RT_NOCRT only it'll return a double quoted string of the result.
634 */
635#ifndef RT_WITHOUT_NOCRT_WRAPPERS
636# define RT_NOCRT(name) nocrt_ ## name
637# define RT_NOCRT_STR(name) "nocrt_" # name
638#else
639# define RT_NOCRT(name) name
640# define RT_NOCRT_STR(name) #name
641#endif
642
643
644
645/** @def RT_LIKELY
646 * Give the compiler a hint that an expression is very likely to hold true.
647 *
648 * Some compilers support explicit branch prediction so that the CPU backend
649 * can hint the processor and also so that code blocks can be reordered such
650 * that the predicted path sees a more linear flow, thus improving cache
651 * behaviour, etc.
652 *
653 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
654 * this compiler feature when present.
655 *
656 * A few notes about the usage:
657 *
658 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
659 * have some _strong_ reason to do otherwise, in which case document it),
660 * and/or RT_LIKELY() with success condition checks, assuming you want
661 * to optimize for the success path.
662 *
663 * - Other than that, if you don't know the likelihood of a test succeeding
664 * from empirical or other 'hard' evidence, don't make predictions unless
665 * you happen to be a Dirk Gently.
666 *
667 * - These macros are meant to be used in places that get executed a lot. It
668 * is wasteful to make predictions in code that is executed seldomly (e.g.
669 * at subsystem initialization time) as the basic block reording that this
670 * affecs can often generate larger code.
671 *
672 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
673 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
674 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
675 *
676 *
677 * @returns the boolean result of the expression.
678 * @param expr The expression that's very likely to be true.
679 * @see RT_UNLIKELY
680 */
681/** @def RT_UNLIKELY
682 * Give the compiler a hint that an expression is highly unlikely hold true.
683 *
684 * See the usage instructions give in the RT_LIKELY() docs.
685 *
686 * @returns the boolean result of the expression.
687 * @param expr The expression that's very unlikely to be true.
688 * @see RT_LIKELY
689 */
690#if defined(__GNUC__)
691# if __GNUC__ >= 3
692# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
693# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
694# else
695# define RT_LIKELY(expr) (expr)
696# define RT_UNLIKELY(expr) (expr)
697# endif
698#else
699# define RT_LIKELY(expr) (expr)
700# define RT_UNLIKELY(expr) (expr)
701#endif
702
703
704/** @def RT_BIT
705 * Make a bitmask for one integer sized bit.
706 * @param bit Bit number.
707 */
708#define RT_BIT(bit) (1U << (bit))
709
710/** @def RT_BIT_32
711 * Make a 32-bit bitmask for one bit.
712 * @param bit Bit number.
713 */
714#define RT_BIT_32(bit) (UINT32_C(1) << (bit))
715
716/** @def RT_BIT_64
717 * Make a 64-bit bitmask for one bit.
718 * @param bit Bit number.
719 */
720#define RT_BIT_64(bit) (UINT64_C(1) << (bit))
721
722/** @def RT_ALIGN
723 * Align macro.
724 * @param u Value to align.
725 * @param uAlignment The alignment. Power of two!
726 *
727 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
728 * When possible use any of the other RT_ALIGN_* macros. And when that's not
729 * possible, make 101% sure that uAlignment is specified with a right sized type.
730 *
731 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
732 * you a 32-bit return value!
733 *
734 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
735 */
736#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
737
738/** @def RT_ALIGN_T
739 * Align macro.
740 * @param u Value to align.
741 * @param uAlignment The alignment. Power of two!
742 * @param type Integer type to use while aligning.
743 * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
744 */
745#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
746
747/** @def RT_ALIGN_32
748 * Align macro for a 32-bit value.
749 * @param u32 Value to align.
750 * @param uAlignment The alignment. Power of two!
751 */
752#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
753
754/** @def RT_ALIGN_64
755 * Align macro for a 64-bit value.
756 * @param u64 Value to align.
757 * @param uAlignment The alignment. Power of two!
758 */
759#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
760
761/** @def RT_ALIGN_Z
762 * Align macro for size_t.
763 * @param cb Value to align.
764 * @param uAlignment The alignment. Power of two!
765 */
766#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
767
768/** @def RT_ALIGN_P
769 * Align macro for pointers.
770 * @param pv Value to align.
771 * @param uAlignment The alignment. Power of two!
772 */
773#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
774
775/** @def RT_ALIGN_PT
776 * Align macro for pointers with type cast.
777 * @param u Value to align.
778 * @param uAlignment The alignment. Power of two!
779 * @param CastType The type to cast the result to.
780 */
781#define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
782
783/** @def RT_ALIGN_R3PT
784 * Align macro for ring-3 pointers with type cast.
785 * @param u Value to align.
786 * @param uAlignment The alignment. Power of two!
787 * @param CastType The type to cast the result to.
788 */
789#define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
790
791/** @def RT_ALIGN_R0PT
792 * Align macro for ring-0 pointers with type cast.
793 * @param u Value to align.
794 * @param uAlignment The alignment. Power of two!
795 * @param CastType The type to cast the result to.
796 */
797#define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
798
799/** @def RT_ALIGN_GCPT
800 * Align macro for GC pointers with type cast.
801 * @param u Value to align.
802 * @param uAlignment The alignment. Power of two!
803 * @param CastType The type to cast the result to.
804 */
805#define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
806
807
808/** @def RT_OFFSETOF
809 * Our own special offsetof() variant.
810 *
811 * This differs from the usual offsetof() in that it's not relying on builtin
812 * compiler stuff and thus can use variables in arrays the structure may
813 * contain. If in this usful to determin the sizes of structures ending
814 * with a variable length field.
815 *
816 * @returns offset into the structure of the specified member.
817 * @param type Structure type.
818 * @param member Member.
819 */
820#define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
821
822/** @def RT_SIZEOFMEMB
823 * Get the size of a structure member.
824 *
825 * @returns size of the structure member.
826 * @param type Structure type.
827 * @param member Member.
828 */
829#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
830
831/** @def RT_ELEMENTS
832 * Calcs the number of elements in an array.
833 * @returns Element count.
834 * @param aArray Array in question.
835 */
836#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
837
838#ifdef RT_OS_OS2
839/* Undefine RT_MAX since there is an unfortunate clash with the max
840 resource type define in os2.h. */
841# undef RT_MAX
842#endif
843
844/** @def RT_MAX
845 * Finds the maximum value.
846 * @returns The higher of the two.
847 * @param Value1 Value 1
848 * @param Value2 Value 2
849 */
850#define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
851
852/** @def RT_MIN
853 * Finds the minimum value.
854 * @returns The lower of the two.
855 * @param Value1 Value 1
856 * @param Value2 Value 2
857 */
858#define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
859
860/** @def RT_ABS
861 * Get the absolute (non-negative) value.
862 * @returns The absolute value of Value.
863 * @param Value The value.
864 */
865#define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
866
867/** @def RT_LOWORD
868 * Gets the low word (=uint16_t) of something. */
869#define RT_LOWORD(a) ((a) & 0xffff)
870
871/** @def RT_HIWORD
872 * Gets the high word (=uint16_t) of a 32 bit something. */
873#define RT_HIWORD(a) ((a) >> 16)
874
875/** @def RT_LOBYTE
876 * Gets the low byte of something. */
877#define RT_LOBYTE(a) ((a) & 0xff)
878
879/** @def RT_HIBYTE
880 * Gets the low byte of a 16 bit something. */
881#define RT_HIBYTE(a) ((a) >> 8)
882
883/** @def RT_BYTE1
884 * Gets first byte of something. */
885#define RT_BYTE1(a) ((a) & 0xff)
886
887/** @def RT_BYTE2
888 * Gets second byte of something. */
889#define RT_BYTE2(a) (((a) >> 8) & 0xff)
890
891/** @def RT_BYTE3
892 * Gets second byte of something. */
893#define RT_BYTE3(a) (((a) >> 16) & 0xff)
894
895/** @def RT_BYTE4
896 * Gets fourth byte of something. */
897#define RT_BYTE4(a) (((a) >> 24) & 0xff)
898
899
900/** @def RT_MAKE_U64
901 * Constructs a uint64_t value from two uint32_t values.
902 */
903#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
904
905/** @def RT_MAKE_U64_FROM_U16
906 * Constructs a uint64_t value from four uint16_t values.
907 */
908#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
909 ( (uint64_t)((uint16_t)(w3)) << 48 \
910 | (uint64_t)((uint16_t)(w2)) << 32 \
911 | (uint32_t)((uint16_t)(w1)) << 16 \
912 | (uint16_t)(w0) )
913
914/** @def RT_MAKE_U64_FROM_U8
915 * Constructs a uint64_t value from eight uint8_t values.
916 */
917#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
918 ( (uint64_t)((uint8_t)(b7)) << 56 \
919 | (uint64_t)((uint8_t)(b6)) << 48 \
920 | (uint64_t)((uint8_t)(b5)) << 40 \
921 | (uint64_t)((uint8_t)(b4)) << 32 \
922 | (uint32_t)((uint8_t)(b3)) << 24 \
923 | (uint32_t)((uint8_t)(b2)) << 16 \
924 | (uint16_t)((uint8_t)(b1)) << 8 \
925 | (uint8_t)(b0) )
926
927/** @def RT_MAKE_U32
928 * Constructs a uint32_t value from two uint16_t values.
929 */
930#define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
931
932/** @def RT_MAKE_U32_FROM_U8
933 * Constructs a uint32_t value from four uint8_t values.
934 */
935#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
936 ( (uint32_t)((uint8_t)(b3)) << 24 \
937 | (uint32_t)((uint8_t)(b2)) << 16 \
938 | (uint16_t)((uint8_t)(b1)) << 8 \
939 | (uint8_t)(b0) )
940/** @todo remove this after uses in VUSBUrb.cpp has been corrected. */
941#define MAKE_U32_FROM_U8(b0,b1,b2,b3) RT_MAKE_U32_FROM_U8(b0,b1,b2,b3)
942
943/** @def RT_MAKE_U16
944 * Constructs a uint32_t value from two uint16_t values.
945 */
946#define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
947
948
949/** @def RT_H2LE_U64
950 * Converts uint64_t value from host to little endian byte order. */
951#define RT_H2LE_U64(u64) (u64)
952
953/** @def RT_H2LE_U32
954 * Converts uint32_t value from host to little endian byte order. */
955#define RT_H2LE_U32(u32) (u32)
956
957/** @def RT_H2LE_U16
958 * Converts uint16_t value from host to little endian byte order. */
959#define RT_H2LE_U16(u16) (u16)
960
961/** @def RT_LE2H_U64
962 * Converts uint64_t value from little endian to host byte order. */
963#define RT_LE2H_U64(u64) (u64)
964
965/** @def RT_LE2H_U32
966 * Converts uint32_t value from little endian to host byte order. */
967#define RT_LE2H_U32(u32) (u32)
968
969/** @def RT_LE2H_U16
970 * Converts uint16_t value from little endian to host byte order. */
971#define RT_LE2H_U16(u16) (u16)
972
973
974/** @def RT_H2BE_U64
975 * Converts uint64_t value from host to big endian byte order. */
976#define RT_H2BE_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
977
978/** @def RT_H2BE_U32
979 * Converts uint32_t value from host to big endian byte order. */
980#define RT_H2BE_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
981
982/** @def RT_H2BE_U16
983 * Converts uint16_t value from host to big endian byte order. */
984#define RT_H2BE_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
985
986/** @def RT_BE2H_U64
987 * Converts uint64_t value from big endian to host byte order. */
988#define RT_BE2H_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
989
990/** @def RT_BE2H_U32
991 * Converts uint32_t value from big endian to host byte order. */
992#define RT_BE2H_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
993
994/** @def RT_BE2H_U16
995 * Converts uint16_t value from big endian to host byte order. */
996#define RT_BE2H_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
997
998
999/** @def RT_H2N_U32
1000 * Converts uint32_t value from host to network byte order. */
1001#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1002
1003/** @def RT_H2N_U16
1004 * Converts uint16_t value from host to network byte order. */
1005#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1006
1007/** @def RT_N2H_U32
1008 * Converts uint32_t value from network to host byte order. */
1009#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1010
1011/** @def RT_N2H_U16
1012 * Converts uint16_t value from network to host byte order. */
1013#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1014
1015
1016/** @def RT_NO_DEPRECATED_MACROS
1017 * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
1018 */
1019#ifndef RT_NO_DEPRECATED_MACROS
1020/** @copydoc BIT
1021 * @deprecated Use RT_BIT.
1022 */
1023# define BIT(bit) RT_BIT(bit)
1024/** @deprecated Use RT_BIT64. */
1025# define BIT64(bit) (1ULL << (bit))
1026/** @copydoc RT_ALIGN_P
1027 * @deprecated use RT_ALIGN_P. */
1028# define ALIGNP(pv, uAlignment) RT_ALIGN_P(pv, uAlignment)
1029/** @copydoc RT_SIZEOFMEMB
1030 * @deprecated Use RT_SIZEOFMEMB. */
1031# define SIZEOFMEMB(type, member) RT_SIZEOFMEMB(type, member)
1032/** @copydoc RT_ELEMENTS
1033 * @deprecated use RT_ELEMENTS. */
1034# define ELEMENTS(aArray) RT_ELEMENTS(aArray)
1035#endif
1036
1037
1038/*
1039 * The BSD sys/param.h + machine/param.h file is a major source of
1040 * namespace pollution. Kill off some of the worse ones unless we're
1041 * compiling kernel code.
1042 */
1043#if defined(RT_OS_DARWIN) \
1044 && !defined(KERNEL) \
1045 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1046 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1047/* sys/param.h: */
1048# undef PSWP
1049# undef PVM
1050# undef PINOD
1051# undef PRIBO
1052# undef PVFS
1053# undef PZERO
1054# undef PSOCK
1055# undef PWAIT
1056# undef PLOCK
1057# undef PPAUSE
1058# undef PUSER
1059# undef PRIMASK
1060# undef MINBUCKET
1061# undef MAXALLOCSAVE
1062# undef FSHIFT
1063# undef FSCALE
1064
1065/* i386/machine.h: */
1066# undef ALIGN
1067# undef ALIGNBYTES
1068# undef DELAY
1069# undef STATUS_WORD
1070# undef USERMODE
1071# undef BASEPRI
1072# undef MSIZE
1073# undef CLSIZE
1074# undef CLSIZELOG2
1075#endif
1076
1077
1078/** @def NULL
1079 * NULL pointer.
1080 */
1081#ifndef NULL
1082# ifdef __cplusplus
1083# define NULL 0
1084# else
1085# define NULL ((void*)0)
1086# endif
1087#endif
1088
1089/** @def NIL_OFFSET
1090 * NIL offset.
1091 * Whenever we use offsets instead of pointers to save space and relocation effort
1092 * NIL_OFFSET shall be used as the equivalent to NULL.
1093 */
1094#define NIL_OFFSET (~0U)
1095
1096/** @def NOREF
1097 * Keeps the compiler from bitching about an unused parameters.
1098 */
1099#define NOREF(var) (void)(var)
1100
1101/** @def Breakpoint
1102 * Emit a debug breakpoint instruction.
1103 *
1104 * Use this for instrumenting a debugging session only!
1105 * No comitted code shall use Breakpoint().
1106 */
1107#ifdef __GNUC__
1108# define Breakpoint() __asm__ __volatile__("int $3\n\t")
1109#endif
1110#ifdef _MSC_VER
1111# define Breakpoint() __asm int 3
1112#endif
1113#if defined(__IBMC__) || defined(__IBMCPP__)
1114# define Breakpoint() __interrupt(3)
1115#endif
1116#ifndef Breakpoint
1117# error "This compiler is not supported!"
1118#endif
1119
1120
1121/** Size Constants
1122 * (Of course, these are binary computer terms, not SI.)
1123 * @{
1124 */
1125/** 1 K (Kilo) (1 024). */
1126#define _1K 0x00000400
1127/** 4 K (Kilo) (4 096). */
1128#define _4K 0x00001000
1129/** 32 K (Kilo) (32 678). */
1130#define _32K 0x00008000
1131/** 64 K (Kilo) (65 536). */
1132#define _64K 0x00010000
1133/** 128 K (Kilo) (131 072). */
1134#define _128K 0x00020000
1135/** 256 K (Kilo) (262 144). */
1136#define _256K 0x00040000
1137/** 512 K (Kilo) (524 288). */
1138#define _512K 0x00080000
1139/** 1 M (Mega) (1 048 576). */
1140#define _1M 0x00100000
1141/** 2 M (Mega) (2 097 152). */
1142#define _2M 0x00200000
1143/** 4 M (Mega) (4 194 304). */
1144#define _4M 0x00400000
1145/** 1 G (Giga) (1 073 741 824). */
1146#define _1G 0x40000000
1147/** 2 G (Giga) (2 147 483 648). (32-bit) */
1148#define _2G32 0x80000000U
1149/** 2 G (Giga) (2 147 483 648). (64-bit) */
1150#define _2G 0x0000000080000000LL
1151/** 4 G (Giga) (4 294 967 296). */
1152#define _4G 0x0000000100000000LL
1153/** 1 T (Tera) (1 099 511 627 776). */
1154#define _1T 0x0000010000000000LL
1155/** 1 P (Peta) (1 125 899 906 842 624). */
1156#define _1P 0x0004000000000000LL
1157/** 1 E (Exa) (1 152 921 504 606 846 976). */
1158#define _1E 0x1000000000000000LL
1159/** 2 E (Exa) (2 305 843 009 213 693 952). */
1160#define _2E 0x2000000000000000ULL
1161/** @} */
1162
1163/** @def VALID_PTR
1164 * Pointer validation macro.
1165 * @param ptr
1166 */
1167#if defined(RT_ARCH_AMD64)
1168# ifdef IN_RING3
1169# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1170# define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1171 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1172# else
1173# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1174 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1175# endif
1176# else /* !IN_RING3 */
1177# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1178 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1179 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1180# endif /* !IN_RING3 */
1181#elif defined(RT_ARCH_X86)
1182# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1183#else
1184# error "Architecture identifier missing / not implemented."
1185#endif
1186
1187
1188/** @def N_
1189 * The \#define N_ is used mark a string for translation. This is usable in
1190 * any part of the code, as it is only used by the tools that create message
1191 * catalogs. This macro is a no-op as far as the compiler and code generation
1192 * is concerned.
1193 *
1194 * If you want to both mark a string for translation and translate it, use _.
1195 */
1196#define N_(s) (s)
1197
1198/** @def _
1199 * The \#define _ is used mark a string for translation and to translate it in
1200 * one step.
1201 *
1202 * If you want to only mark a string for translation, use N_.
1203 */
1204#define _(s) gettext(s)
1205
1206
1207/** @def __PRETTY_FUNCTION__
1208 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
1209 */
1210#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1211# define __PRETTY_FUNCTION__ __FUNCTION__
1212#endif
1213
1214
1215/** @def RT_STRICT
1216 * The \#define RT_STRICT controls whether or not assertions and other runtime checks
1217 * should be compiled in or not.
1218 *
1219 * If you want assertions which are not a subject to compile time options use
1220 * the AssertRelease*() flavors.
1221 */
1222#if !defined(RT_STRICT) && defined(DEBUG)
1223# define RT_STRICT
1224#endif
1225
1226/** Source position. */
1227#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
1228
1229/** Source position declaration. */
1230#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
1231
1232/** Source position arguments. */
1233#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
1234
1235/** @} */
1236
1237
1238/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
1239 * @ingroup grp_rt_cdefs
1240 * @{
1241 */
1242
1243#ifdef __cplusplus
1244
1245/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
1246 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
1247 * resolver. The following snippet clearly demonstrates the code causing this
1248 * error:
1249 * @code
1250 * class A
1251 * {
1252 * public:
1253 * operator bool() const { return false; }
1254 * operator int*() const { return NULL; }
1255 * };
1256 * int main()
1257 * {
1258 * A a;
1259 * if (!a);
1260 * if (a && 0);
1261 * return 0;
1262 * }
1263 * @endcode
1264 * The code itself seems pretty valid to me and GCC thinks the same.
1265 *
1266 * This macro fixes the compiler error by explicitly overloading implicit
1267 * global operators !, && and || that take the given class instance as one of
1268 * their arguments.
1269 *
1270 * The best is to use this macro right after the class declaration.
1271 *
1272 * @note The macro expands to nothing for compilers other than MSVC.
1273 *
1274 * @param Cls Class to apply the workaround to
1275 */
1276#if defined(_MSC_VER)
1277# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
1278 inline bool operator! (const Cls &that) { return !bool (that); } \
1279 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
1280 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
1281 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
1282 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
1283#else
1284# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
1285#endif
1286
1287/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
1288 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
1289 *
1290 * @param Tpl Name of the template class to apply the workaround to
1291 * @param ArgsDecl arguments of the template, as declared in |<>| after the
1292 * |template| keyword, including |<>|
1293 * @param Args arguments of the template, as specified in |<>| after the
1294 * template class name when using the, including |<>|
1295 *
1296 * Example:
1297 * @code
1298 * // template class declaration
1299 * template <class C>
1300 * class Foo { ... };
1301 * // applied workaround
1302 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
1303 * @endcode
1304 */
1305#if defined(_MSC_VER)
1306# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
1307 template ArgsDecl \
1308 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
1309 template ArgsDecl \
1310 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
1311 template ArgsDecl \
1312 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
1313 template ArgsDecl \
1314 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
1315 template ArgsDecl \
1316 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
1317#else
1318# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
1319#endif
1320
1321
1322/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
1323 * Declares the copy constructor and the assignment operation as inlined no-ops
1324 * (non-existent functions) for the given class. Use this macro inside the
1325 * private section if you want to effectively disable these operations for your
1326 * class.
1327 *
1328 * @param Cls class name to declare for
1329 */
1330
1331#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
1332 inline Cls (const Cls &); \
1333 inline Cls &operator= (const Cls &);
1334
1335
1336/** @def DECLARE_CLS_NEW_DELETE_NOOP
1337 * Declares the new and delete operations as no-ops (non-existent functions)
1338 * for the given class. Use this macro inside the private section if you want
1339 * to effectively limit creating class instances on the stack only.
1340 *
1341 * @note The destructor of the given class must not be virtual, otherwise a
1342 * compile time error will occur. Note that this is not a drawback: having
1343 * the virtual destructor for a stack-based class is absolutely useless
1344 * (the real class of the stack-based instance is always known to the compiler
1345 * at compile time, so it will always call the correct destructor).
1346 *
1347 * @param Cls class name to declare for
1348 */
1349#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
1350 inline static void *operator new (size_t); \
1351 inline static void operator delete (void *);
1352
1353#endif /* defined(__cplusplus) */
1354
1355/** @} */
1356
1357#endif
1358
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette