VirtualBox

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

Last change on this file since 4878 was 4852, checked in by vboxsync, 17 years ago

CTR3R0TYPE isn't needed.

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