VirtualBox

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

Last change on this file since 4394 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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