VirtualBox

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

Last change on this file since 21086 was 21084, checked in by vboxsync, 16 years ago

iprt/cdefs.h: RT_DECL_CLASS.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 58.6 KB
Line 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_cdefs_h
31#define ___iprt_cdefs_h
32
33
34/** @defgroup grp_rt_cdefs IPRT Common Definitions and Macros
35 * @{
36 */
37
38/*
39 * Include sys/cdefs.h if present, if not define the stuff we need.
40 */
41#ifdef HAVE_SYS_CDEFS_H
42# if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
43# error "oops"
44# endif
45# include <sys/cdefs.h>
46#else
47
48/** @def RT_C_DECLS_BEGIN
49 * Used to start a block of function declarations which are shared
50 * between C and C++ program.
51 */
52
53/** @def RT_C_DECLS_END
54 * Used to end a block of function declarations which are shared
55 * between C and C++ program.
56 */
57
58# if defined(__cplusplus)
59# define RT_C_DECLS_BEGIN extern "C" {
60# define RT_C_DECLS_END }
61# else
62# define RT_C_DECLS_BEGIN
63# define RT_C_DECLS_END
64# endif
65
66#endif
67
68
69/*
70 * Shut up DOXYGEN warnings and guide it properly thru the code.
71 */
72#ifdef DOXYGEN_RUNNING
73#define __AMD64__
74#define __X86__
75#define RT_ARCH_AMD64
76#define RT_ARCH_X86
77#define IN_RING0
78#define IN_RING3
79#define IN_RC
80#define IN_RC
81#define IN_RT_GC
82#define IN_RT_R0
83#define IN_RT_R3
84#define IN_RT_STATIC
85#define RT_STRICT
86#define Breakpoint
87#define RT_NO_DEPRECATED_MACROS
88#endif /* DOXYGEN_RUNNING */
89
90/** @def RT_ARCH_X86
91 * Indicates that we're compiling for the X86 architecture.
92 */
93
94/** @def RT_ARCH_AMD64
95 * Indicates that we're compiling for the AMD64 architecture.
96 */
97#if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
98# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
99# define RT_ARCH_AMD64
100# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
101# define RT_ARCH_X86
102# else /* PORTME: append test for new archs. */
103# error "Check what predefined macros your compiler uses to indicate architecture."
104# endif
105#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
106# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
107#endif
108
109
110/** @def __X86__
111 * Indicates that we're compiling for the X86 architecture.
112 * @deprecated
113 */
114
115/** @def __AMD64__
116 * Indicates that we're compiling for the AMD64 architecture.
117 * @deprecated
118 */
119#if !defined(__X86__) && !defined(__AMD64__)
120# if defined(RT_ARCH_AMD64)
121# define __AMD64__
122# elif defined(RT_ARCH_X86)
123# define __X86__
124# else
125# error "Check what predefined macros your compiler uses to indicate architecture."
126# endif
127#elif defined(__X86__) && defined(__AMD64__)
128# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
129#elif defined(__X86__) && !defined(RT_ARCH_X86)
130# error "Both __X86__ without RT_ARCH_X86!"
131#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
132# error "Both __AMD64__ without RT_ARCH_AMD64!"
133#endif
134
135/** @def IN_RING0
136 * Used to indicate that we're compiling code which is running
137 * in Ring-0 Host Context.
138 */
139
140/** @def IN_RING3
141 * Used to indicate that we're compiling code which is running
142 * in Ring-3 Host Context.
143 */
144
145/** @def IN_RC
146 * Used to indicate that we're compiling code which is running
147 * in the Raw-mode Context (implies R0).
148 */
149#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC) && !defined(IN_RC)
150# error "You must define which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
151#endif
152#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
153 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
154 || (defined(IN_RC) && (defined(IN_RING3) || defined(IN_RING0)) )
155# error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
156#endif
157
158
159/** @def ARCH_BITS
160 * Defines the bit count of the current context.
161 */
162#if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
163# if defined(RT_ARCH_AMD64)
164# define ARCH_BITS 64
165# else
166# define ARCH_BITS 32
167# endif
168#endif
169
170/** @def HC_ARCH_BITS
171 * Defines the host architecture bit count.
172 */
173#if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
174# ifndef IN_RC
175# define HC_ARCH_BITS ARCH_BITS
176# else
177# define HC_ARCH_BITS 32
178# endif
179#endif
180
181/** @def GC_ARCH_BITS
182 * Defines the guest architecture bit count.
183 */
184#if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
185# ifdef VBOX_WITH_64_BITS_GUESTS
186# define GC_ARCH_BITS 64
187# else
188# define GC_ARCH_BITS 32
189# endif
190#endif
191
192/** @def R3_ARCH_BITS
193 * Defines the host ring-3 architecture bit count.
194 */
195#if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
196# ifdef IN_RING3
197# define R3_ARCH_BITS ARCH_BITS
198# else
199# define R3_ARCH_BITS HC_ARCH_BITS
200# endif
201#endif
202
203/** @def R0_ARCH_BITS
204 * Defines the host ring-0 architecture bit count.
205 */
206#if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
207# ifdef IN_RING0
208# define R0_ARCH_BITS ARCH_BITS
209# else
210# define R0_ARCH_BITS HC_ARCH_BITS
211# endif
212#endif
213
214/** @def GC_ARCH_BITS
215 * Defines the guest architecture bit count.
216 */
217#if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
218# ifdef IN_RC
219# define GC_ARCH_BITS ARCH_BITS
220# else
221# define GC_ARCH_BITS 32
222# endif
223#endif
224
225
226/** @def CTXTYPE
227 * Declare a type differently in GC, R3 and R0.
228 *
229 * @param GCType The GC type.
230 * @param R3Type The R3 type.
231 * @param R0Type The R0 type.
232 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
233 */
234#ifdef IN_RC
235# define CTXTYPE(GCType, R3Type, R0Type) GCType
236#elif defined(IN_RING3)
237# define CTXTYPE(GCType, R3Type, R0Type) R3Type
238#else
239# define CTXTYPE(GCType, R3Type, R0Type) R0Type
240#endif
241
242/** @def RCPTRTYPE
243 * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
244 * both HC and RC. The main purpose is to make sure structures have the same
245 * size when built for different architectures.
246 *
247 * @param RCType The RC type.
248 */
249#define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
250
251/** @def R3R0PTRTYPE
252 * Declare a pointer which is used in HC, is explicitly valid in ring 3 and 0,
253 * but appears in structure(s) used by both HC and GC. The main purpose is to
254 * make sure structures have the same size when built for different architectures.
255 *
256 * @param R3R0Type The R3R0 type.
257 * @remarks This used to be called HCPTRTYPE.
258 */
259#define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
260
261/** @def R3PTRTYPE
262 * Declare a pointer which is used in R3 but appears in structure(s) used by
263 * both HC and GC. The main purpose is to make sure structures have the same
264 * size when built for different architectures.
265 *
266 * @param R3Type The R3 type.
267 */
268#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
269
270/** @def R0PTRTYPE
271 * Declare a pointer which is used in R0 but appears in structure(s) used by
272 * both HC and GC. The main purpose is to make sure structures have the same
273 * size when built for different architectures.
274 *
275 * @param R0Type The R0 type.
276 */
277#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
278
279/** @def CTXSUFF
280 * Adds the suffix of the current context to the passed in
281 * identifier name. The suffix is HC or GC.
282 *
283 * This is macro should only be used in shared code to avoid a forest of ifdefs.
284 * @param var Identifier name.
285 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
286 */
287/** @def OTHERCTXSUFF
288 * Adds the suffix of the other context to the passed in
289 * identifier name. The suffix is HC or GC.
290 *
291 * This is macro should only be used in shared code to avoid a forest of ifdefs.
292 * @param var Identifier name.
293 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
294 */
295#ifdef IN_RC
296# define CTXSUFF(var) var##GC
297# define OTHERCTXSUFF(var) var##HC
298#else
299# define CTXSUFF(var) var##HC
300# define OTHERCTXSUFF(var) var##GC
301#endif
302
303/** @def CTXALLSUFF
304 * Adds the suffix of the current context to the passed in
305 * identifier name. The suffix is R3, R0 or GC.
306 *
307 * This is macro should only be used in shared code to avoid a forest of ifdefs.
308 * @param var Identifier name.
309 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
310 */
311#ifdef IN_RC
312# define CTXALLSUFF(var) var##GC
313#elif defined(IN_RING0)
314# define CTXALLSUFF(var) var##R0
315#else
316# define CTXALLSUFF(var) var##R3
317#endif
318
319/** @def CTX_SUFF
320 * Adds the suffix of the current context to the passed in
321 * identifier name. The suffix is R3, R0 or RC.
322 *
323 * This is macro should only be used in shared code to avoid a forest of ifdefs.
324 * @param var Identifier name.
325 *
326 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
327 */
328#ifdef IN_RC
329# define CTX_SUFF(var) var##RC
330#elif defined(IN_RING0)
331# define CTX_SUFF(var) var##R0
332#else
333# define CTX_SUFF(var) var##R3
334#endif
335
336/** @def CTX_SUFF_Z
337 * Adds the suffix of the current context to the passed in
338 * identifier name, combining RC and R0 into RZ.
339 * The suffix thus is R3 or RZ.
340 *
341 * This is macro should only be used in shared code to avoid a forest of ifdefs.
342 * @param var Identifier name.
343 *
344 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
345 */
346#ifdef IN_RING3
347# define CTX_SUFF_Z(var) var##R3
348#else
349# define CTX_SUFF_Z(var) var##RZ
350#endif
351
352
353/** @def CTXMID
354 * Adds the current context as a middle name of an identifier name
355 * The middle name is HC or GC.
356 *
357 * This is macro should only be used in shared code to avoid a forest of ifdefs.
358 * @param first First name.
359 * @param last Surname.
360 */
361/** @def OTHERCTXMID
362 * Adds the other context as a middle name of an identifier name
363 * The middle name is HC or GC.
364 *
365 * This is macro should only be used in shared code to avoid a forest of ifdefs.
366 * @param first First name.
367 * @param last Surname.
368 * @deprecated use CTX_MID or CTX_MID_Z
369 */
370#ifdef IN_RC
371# define CTXMID(first, last) first##GC##last
372# define OTHERCTXMID(first, last) first##HC##last
373#else
374# define CTXMID(first, last) first##HC##last
375# define OTHERCTXMID(first, last) first##GC##last
376#endif
377
378/** @def CTXALLMID
379 * Adds the current context as a middle name of an identifier name.
380 * The middle name is R3, R0 or GC.
381 *
382 * This is macro should only be used in shared code to avoid a forest of ifdefs.
383 * @param first First name.
384 * @param last Surname.
385 * @deprecated use CTX_MID or CTX_MID_Z
386 */
387#ifdef IN_RC
388# define CTXALLMID(first, last) first##GC##last
389#elif defined(IN_RING0)
390# define CTXALLMID(first, last) first##R0##last
391#else
392# define CTXALLMID(first, last) first##R3##last
393#endif
394
395/** @def CTX_MID
396 * Adds the current context as a middle name of an identifier name.
397 * The middle name is R3, R0 or RC.
398 *
399 * This is macro should only be used in shared code to avoid a forest of ifdefs.
400 * @param first First name.
401 * @param last Surname.
402 */
403#ifdef IN_RC
404# define CTX_MID(first, last) first##RC##last
405#elif defined(IN_RING0)
406# define CTX_MID(first, last) first##R0##last
407#else
408# define CTX_MID(first, last) first##R3##last
409#endif
410
411/** @def CTX_MID_Z
412 * Adds the current context as a middle name of an identifier name, combining RC
413 * and R0 into RZ.
414 * The middle name thus is either R3 or RZ.
415 *
416 * This is macro should only be used in shared code to avoid a forest of ifdefs.
417 * @param first First name.
418 * @param last Surname.
419 */
420#ifdef IN_RING3
421# define CTX_MID_Z(first, last) first##R3##last
422#else
423# define CTX_MID_Z(first, last) first##RZ##last
424#endif
425
426
427/** @def R3STRING
428 * A macro which in GC and R0 will return a dummy string while in R3 it will return
429 * the parameter.
430 *
431 * This is typically used to wrap description strings in structures shared
432 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
433 *
434 * @param pR3String The R3 string. Only referenced in R3.
435 * @see R0STRING and GCSTRING
436 */
437#ifdef IN_RING3
438# define R3STRING(pR3String) (pR3String)
439#else
440# define R3STRING(pR3String) ("<R3_STRING>")
441#endif
442
443/** @def R0STRING
444 * A macro which in GC and R3 will return a dummy string while in R0 it will return
445 * the parameter.
446 *
447 * This is typically used to wrap description strings in structures shared
448 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
449 *
450 * @param pR0String The R0 string. Only referenced in R0.
451 * @see R3STRING and GCSTRING
452 */
453#ifdef IN_RING0
454# define R0STRING(pR0String) (pR0String)
455#else
456# define R0STRING(pR0String) ("<R0_STRING>")
457#endif
458
459/** @def RCSTRING
460 * A macro which in R3 and R0 will return a dummy string while in RC it will return
461 * the parameter.
462 *
463 * This is typically used to wrap description strings in structures shared
464 * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
465 *
466 * @param pR0String The RC string. Only referenced in RC.
467 * @see R3STRING, R0STRING
468 */
469#ifdef IN_RC
470# define RCSTRING(pRCString) (pRCString)
471#else
472# define RCSTRING(pRCString) ("<RC_STRING>")
473#endif
474
475
476/** @def RT_NOTHING
477 * A macro that expands to nothing.
478 * This is primarily intended as a dummy argument for macros to avoid the
479 * undefined behavior passing empty arguments to an macro (ISO C90 and C++98,
480 * gcc v4.4 warns about it).
481 */
482#define RT_NOTHING
483
484
485/** @def RTCALL
486 * The standard calling convention for the Runtime interfaces.
487 */
488#ifdef _MSC_VER
489# define RTCALL __cdecl
490#elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
491# define RTCALL __attribute__((cdecl,regparm(0)))
492#else
493# define RTCALL
494#endif
495
496/** @def RT_NO_THROW
497 * How to express that a function doesn't throw C++ exceptions
498 * and the compiler can thus save itself the bother of trying
499 * to catch any of them. Put this between the closing parenthesis
500 * and the semicolon in function prototypes (and implementation if C++).
501 */
502#if defined(__cplusplus) \
503 && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
504 || (defined(__GNUC__) && defined(__EXCEPTIONS)))
505# define RT_NO_THROW throw()
506#else
507# define RT_NO_THROW
508#endif
509
510/** @def DECLEXPORT
511 * How to declare an exported function.
512 * @param type The return type of the function declaration.
513 */
514#if defined(_MSC_VER) || defined(RT_OS_OS2)
515# define DECLEXPORT(type) __declspec(dllexport) type
516#elif defined(RT_USE_VISIBILITY_DEFAULT)
517# define DECLEXPORT(type) __attribute__((visibility("default"))) type
518#else
519# define DECLEXPORT(type) type
520#endif
521
522/** @def DECLIMPORT
523 * How to declare an imported function.
524 * @param type The return type of the function declaration.
525 */
526#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
527# define DECLIMPORT(type) __declspec(dllimport) type
528#else
529# define DECLIMPORT(type) type
530#endif
531
532/** @def DECLHIDDEN
533 * How to declare a non-exported function or variable.
534 * @param type The return type of the function or the data type of the variable.
535 */
536#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN)
537# define DECLHIDDEN(type) type
538#else
539# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
540#endif
541
542/** @def DECLASM
543 * How to declare an internal assembly function.
544 * @param type The return type of the function declaration.
545 */
546#ifdef __cplusplus
547# ifdef _MSC_VER
548# define DECLASM(type) extern "C" type __cdecl
549# else
550# define DECLASM(type) extern "C" type
551# endif
552#else
553# ifdef _MSC_VER
554# define DECLASM(type) type __cdecl
555# else
556# define DECLASM(type) type
557# endif
558#endif
559
560/** @def DECLASMTYPE
561 * How to declare an internal assembly function type.
562 * @param type The return type of the function.
563 */
564#ifdef _MSC_VER
565# define DECLASMTYPE(type) type __cdecl
566#else
567# define DECLASMTYPE(type) type
568#endif
569
570/** @def DECLNORETURN
571 * How to declare a function which does not return.
572 * @note: This macro can be combined with other macros, for example
573 * @code
574 * EMR3DECL(DECLNORETURN(void)) foo(void);
575 * @endcode
576 */
577#ifdef _MSC_VER
578# define DECLNORETURN(type) __declspec(noreturn) type
579#elif defined(__GNUC__)
580# define DECLNORETURN(type) __attribute__((noreturn)) type
581#else
582# define DECLNORETURN(type) type
583#endif
584
585/** @def DECLCALLBACK
586 * How to declare an call back function type.
587 * @param type The return type of the function declaration.
588 */
589#define DECLCALLBACK(type) type RTCALL
590
591/** @def DECLCALLBACKPTR
592 * How to declare an call back function pointer.
593 * @param type The return type of the function declaration.
594 * @param name The name of the variable member.
595 */
596#define DECLCALLBACKPTR(type, name) type (RTCALL * name)
597
598/** @def DECLCALLBACKMEMBER
599 * How to declare an call back function pointer member.
600 * @param type The return type of the function declaration.
601 * @param name The name of the struct/union/class member.
602 */
603#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
604
605/** @def DECLR3CALLBACKMEMBER
606 * How to declare an call back function pointer member - R3 Ptr.
607 * @param type The return type of the function declaration.
608 * @param name The name of the struct/union/class member.
609 * @param args The argument list enclosed in parentheses.
610 */
611#ifdef IN_RING3
612# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
613#else
614# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
615#endif
616
617/** @def DECLRCCALLBACKMEMBER
618 * How to declare an call back function pointer member - RC Ptr.
619 * @param type The return type of the function declaration.
620 * @param name The name of the struct/union/class member.
621 * @param args The argument list enclosed in parentheses.
622 */
623#ifdef IN_RC
624# define DECLRCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
625#else
626# define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
627#endif
628
629/** @def DECLR0CALLBACKMEMBER
630 * How to declare an call back function pointer member - R0 Ptr.
631 * @param type The return type of the function declaration.
632 * @param name The name of the struct/union/class member.
633 * @param args The argument list enclosed in parentheses.
634 */
635#ifdef IN_RING0
636# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
637#else
638# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
639#endif
640
641/** @def DECLINLINE
642 * How to declare a function as inline.
643 * @param type The return type of the function declaration.
644 * @remarks Don't use this macro on C++ methods.
645 */
646#ifdef __GNUC__
647# define DECLINLINE(type) static __inline__ type
648#elif defined(__cplusplus)
649# define DECLINLINE(type) inline type
650#elif defined(_MSC_VER)
651# define DECLINLINE(type) _inline type
652#elif defined(__IBMC__)
653# define DECLINLINE(type) _Inline type
654#else
655# define DECLINLINE(type) inline type
656#endif
657
658
659/** @def DECL_FORCE_INLINE
660 * How to declare a function as inline and try convince the compiler to always
661 * inline it regardless of optimization switches.
662 * @param type The return type of the function declaration.
663 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
664 */
665#ifdef __GNUC__
666# define DECL_FORCE_INLINE(type) __attribute__((always_inline)) DECLINLINE(type)
667#elif defined(_MSC_VER)
668# define DECL_FORCE_INLINE(type) __forceinline type
669#else
670# define DECL_FORCE_INLINE(type) DECLINLINE(type)
671#endif
672
673
674/** @def DECL_NO_INLINE
675 * How to declare a function telling the compiler not to inline it.
676 * @param scope The function scope, static or RT_NOTHING.
677 * @param type The return type of the function declaration.
678 * @remarks Don't use this macro on C++ methods.
679 */
680#ifdef __GNUC__
681# define DECL_NO_INLINE(scope,type) __attribute__((noinline)) scope type
682#elif defined(_MSC_VER)
683# define DECL_NO_INLINE(scope,type) __declspec(noline) scope type
684#else
685# define DECL_NO_INLINE(scope,type) scope type
686#endif
687
688
689/** @def IN_RT_STATIC
690 * Used to indicate whether we're linking against a static IPRT
691 * or not. The IPRT symbols will be declared as hidden (if
692 * supported). Note that this define has no effect without setting
693 * IN_RT_R0, IN_RT_R3 or IN_RT_GC indicators are set first.
694 */
695
696/** @def IN_RT_R0
697 * Used to indicate whether we're inside the same link module as
698 * the HC Ring-0 Runtime Library.
699 */
700/** @def RTR0DECL(type)
701 * Runtime Library HC Ring-0 export or import declaration.
702 * @param type The return type of the function declaration.
703 */
704#ifdef IN_RT_R0
705# ifdef IN_RT_STATIC
706# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
707# else
708# define RTR0DECL(type) DECLEXPORT(type) RTCALL
709# endif
710#else
711# define RTR0DECL(type) DECLIMPORT(type) RTCALL
712#endif
713
714/** @def IN_RT_R3
715 * Used to indicate whether we're inside the same link module as
716 * the HC Ring-3 Runtime Library.
717 */
718/** @def RTR3DECL(type)
719 * Runtime Library HC Ring-3 export or import declaration.
720 * @param type The return type of the function declaration.
721 */
722#ifdef IN_RT_R3
723# ifdef IN_RT_STATIC
724# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
725# else
726# define RTR3DECL(type) DECLEXPORT(type) RTCALL
727# endif
728#else
729# define RTR3DECL(type) DECLIMPORT(type) RTCALL
730#endif
731
732/** @def IN_RT_GC
733 * Used to indicate whether we're inside the same link module as
734 * the GC Runtime Library.
735 */
736/** @def RTGCDECL(type)
737 * Runtime Library HC Ring-3 export or import declaration.
738 * @param type The return type of the function declaration.
739 */
740#ifdef IN_RT_GC
741# ifdef IN_RT_STATIC
742# define RTGCDECL(type) DECLHIDDEN(type) RTCALL
743# else
744# define RTGCDECL(type) DECLEXPORT(type) RTCALL
745# endif
746#else
747# define RTGCDECL(type) DECLIMPORT(type) RTCALL
748#endif
749
750/** @def RTDECL(type)
751 * Runtime Library export or import declaration.
752 * Functions declared using this macro exists in all contexts.
753 * @param type The return type of the function declaration.
754 */
755#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
756# ifdef IN_RT_STATIC
757# define RTDECL(type) DECLHIDDEN(type) RTCALL
758# else
759# define RTDECL(type) DECLEXPORT(type) RTCALL
760# endif
761#else
762# define RTDECL(type) DECLIMPORT(type) RTCALL
763#endif
764
765/** @def RTDATADECL(type)
766 * Runtime Library export or import declaration.
767 * Data declared using this macro exists in all contexts.
768 * @param type The return type of the function declaration.
769 */
770#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
771# ifdef IN_RT_STATIC
772# define RTDATADECL(type) DECLHIDDEN(type)
773# else
774# define RTDATADECL(type) DECLEXPORT(type)
775# endif
776#else
777# define RTDATADECL(type) DECLIMPORT(type)
778#endif
779
780/** @def RT_DECL_CLASS
781 * Declares an class living in the runtime.
782 */
783#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
784# ifdef IN_RT_STATIC
785# define RT_DECL_CLASS
786# else
787# define RT_DECL_CLASS DECLEXPORT_CLASS
788# endif
789#else
790# define RT_DECL_CLASS DECLIMPORT_CLASS
791#endif
792
793
794/** @def RT_NOCRT
795 * Symbol name wrapper for the No-CRT bits.
796 *
797 * In order to coexist in the same process as other CRTs, we need to
798 * decorate the symbols such that they don't conflict the ones in the
799 * other CRTs. The result of such conflicts / duplicate symbols can
800 * confuse the dynamic loader on Unix like systems.
801 *
802 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
803 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
804 * wrapped names.
805 */
806/** @def RT_NOCRT_STR
807 * Same as RT_NOCRT only it'll return a double quoted string of the result.
808 */
809#ifndef RT_WITHOUT_NOCRT_WRAPPERS
810# define RT_NOCRT(name) nocrt_ ## name
811# define RT_NOCRT_STR(name) "nocrt_" # name
812#else
813# define RT_NOCRT(name) name
814# define RT_NOCRT_STR(name) #name
815#endif
816
817
818
819/** @def RT_LIKELY
820 * Give the compiler a hint that an expression is very likely to hold true.
821 *
822 * Some compilers support explicit branch prediction so that the CPU backend
823 * can hint the processor and also so that code blocks can be reordered such
824 * that the predicted path sees a more linear flow, thus improving cache
825 * behaviour, etc.
826 *
827 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
828 * this compiler feature when present.
829 *
830 * A few notes about the usage:
831 *
832 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
833 * have some _strong_ reason to do otherwise, in which case document it),
834 * and/or RT_LIKELY() with success condition checks, assuming you want
835 * to optimize for the success path.
836 *
837 * - Other than that, if you don't know the likelihood of a test succeeding
838 * from empirical or other 'hard' evidence, don't make predictions unless
839 * you happen to be a Dirk Gently.
840 *
841 * - These macros are meant to be used in places that get executed a lot. It
842 * is wasteful to make predictions in code that is executed rarely (e.g.
843 * at subsystem initialization time) as the basic block reordering that this
844 * affects can often generate larger code.
845 *
846 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
847 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
848 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
849 *
850 *
851 * @returns the boolean result of the expression.
852 * @param expr The expression that's very likely to be true.
853 * @see RT_UNLIKELY
854 */
855/** @def RT_UNLIKELY
856 * Give the compiler a hint that an expression is highly unlikely to hold true.
857 *
858 * See the usage instructions give in the RT_LIKELY() docs.
859 *
860 * @returns the boolean result of the expression.
861 * @param expr The expression that's very unlikely to be true.
862 * @see RT_LIKELY
863 */
864#if defined(__GNUC__)
865# if __GNUC__ >= 3
866# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
867# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
868# else
869# define RT_LIKELY(expr) (expr)
870# define RT_UNLIKELY(expr) (expr)
871# endif
872#else
873# define RT_LIKELY(expr) (expr)
874# define RT_UNLIKELY(expr) (expr)
875#endif
876
877
878/** @def RT_BIT
879 * Convert a bit number into an integer bitmask (unsigned).
880 * @param bit The bit number.
881 */
882#define RT_BIT(bit) ( 1U << (bit) )
883
884/** @def RT_BIT_32
885 * Convert a bit number into a 32-bit bitmask (unsigned).
886 * @param bit The bit number.
887 */
888#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
889
890/** @def RT_BIT_64
891 * Convert a bit number into a 64-bit bitmask (unsigned).
892 * @param bit The bit number.
893 */
894#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
895
896/** @def RT_ALIGN
897 * Align macro.
898 * @param u Value to align.
899 * @param uAlignment The alignment. Power of two!
900 *
901 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
902 * When possible use any of the other RT_ALIGN_* macros. And when that's not
903 * possible, make 101% sure that uAlignment is specified with a right sized type.
904 *
905 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
906 * you a 32-bit return value!
907 *
908 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
909 */
910#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
911
912/** @def RT_ALIGN_T
913 * Align macro.
914 * @param u Value to align.
915 * @param uAlignment The alignment. Power of two!
916 * @param type Integer type to use while aligning.
917 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
918 */
919#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
920
921/** @def RT_ALIGN_32
922 * Align macro for a 32-bit value.
923 * @param u32 Value to align.
924 * @param uAlignment The alignment. Power of two!
925 */
926#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
927
928/** @def RT_ALIGN_64
929 * Align macro for a 64-bit value.
930 * @param u64 Value to align.
931 * @param uAlignment The alignment. Power of two!
932 */
933#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
934
935/** @def RT_ALIGN_Z
936 * Align macro for size_t.
937 * @param cb Value to align.
938 * @param uAlignment The alignment. Power of two!
939 */
940#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
941
942/** @def RT_ALIGN_P
943 * Align macro for pointers.
944 * @param pv Value to align.
945 * @param uAlignment The alignment. Power of two!
946 */
947#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
948
949/** @def RT_ALIGN_PT
950 * Align macro for pointers with type cast.
951 * @param u Value to align.
952 * @param uAlignment The alignment. Power of two!
953 * @param CastType The type to cast the result to.
954 */
955#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
956
957/** @def RT_ALIGN_R3PT
958 * Align macro for ring-3 pointers with type cast.
959 * @param u Value to align.
960 * @param uAlignment The alignment. Power of two!
961 * @param CastType The type to cast the result to.
962 */
963#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
964
965/** @def RT_ALIGN_R0PT
966 * Align macro for ring-0 pointers with type cast.
967 * @param u Value to align.
968 * @param uAlignment The alignment. Power of two!
969 * @param CastType The type to cast the result to.
970 */
971#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
972
973/** @def RT_ALIGN_GCPT
974 * Align macro for GC pointers with type cast.
975 * @param u Value to align.
976 * @param uAlignment The alignment. Power of two!
977 * @param CastType The type to cast the result to.
978 */
979#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
980
981
982/** @def RT_OFFSETOF
983 * Our own special offsetof() variant, returns a signed result.
984 *
985 * This differs from the usual offsetof() in that it's not relying on builtin
986 * compiler stuff and thus can use variables in arrays the structure may
987 * contain. This is useful to determine the sizes of structures ending
988 * with a variable length field.
989 *
990 * @returns offset into the structure of the specified member. signed.
991 * @param type Structure type.
992 * @param member Member.
993 */
994#define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
995
996/** @def RT_UOFFSETOF
997 * Our own special offsetof() variant, returns an unsigned result.
998 *
999 * This differs from the usual offsetof() in that it's not relying on builtin
1000 * compiler stuff and thus can use variables in arrays the structure may
1001 * contain. This is useful to determine the sizes of structures ending
1002 * with a variable length field.
1003 *
1004 * @returns offset into the structure of the specified member. unsigned.
1005 * @param type Structure type.
1006 * @param member Member.
1007 */
1008#define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
1009
1010/** @def RT_OFFSETOF_ADD
1011 * RT_OFFSETOF with an addend.
1012 *
1013 * @returns offset into the structure of the specified member. signed.
1014 * @param type Structure type.
1015 * @param member Member.
1016 * @param addend The addend to add to the offset.
1017 */
1018#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
1019
1020/** @def RT_UOFFSETOF_ADD
1021 * RT_UOFFSETOF with an addend.
1022 *
1023 * @returns offset into the structure of the specified member. signed.
1024 * @param type Structure type.
1025 * @param member Member.
1026 * @param addend The addend to add to the offset.
1027 */
1028#define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
1029
1030/** @def RT_SIZEOFMEMB
1031 * Get the size of a structure member.
1032 *
1033 * @returns size of the structure member.
1034 * @param type Structure type.
1035 * @param member Member.
1036 */
1037#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
1038
1039/** @def RT_FROM_MEMBER
1040 * Convert a pointer to a structure member into a pointer to the structure.
1041 * @returns pointer to the structure.
1042 * @param pMember Pointer to the member.
1043 * @param Type Strucutre type.
1044 * @param Member Member name.
1045 */
1046#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) + RT_UOFFSETOF(Type, Member)) )
1047
1048/** @def RT_ELEMENTS
1049 * Calculates the number of elements in a statically sized array.
1050 * @returns Element count.
1051 * @param aArray Array in question.
1052 */
1053#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
1054
1055#ifdef RT_OS_OS2
1056/* Undefine RT_MAX since there is an unfortunate clash with the max
1057 resource type define in os2.h. */
1058# undef RT_MAX
1059#endif
1060
1061/** @def RT_MAX
1062 * Finds the maximum value.
1063 * @returns The higher of the two.
1064 * @param Value1 Value 1
1065 * @param Value2 Value 2
1066 */
1067#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1068
1069/** @def RT_MIN
1070 * Finds the minimum value.
1071 * @returns The lower of the two.
1072 * @param Value1 Value 1
1073 * @param Value2 Value 2
1074 */
1075#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
1076
1077/** @def RT_ABS
1078 * Get the absolute (non-negative) value.
1079 * @returns The absolute value of Value.
1080 * @param Value The value.
1081 */
1082#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
1083
1084/** @def RT_LODWORD
1085 * Gets the low dword (=uint32_t) of something. */
1086#define RT_LODWORD(a) ( (uint32_t)(a) )
1087
1088/** @def RT_HIDWORD
1089 * Gets the high dword (=uint32_t) of a 64-bit of something. */
1090#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
1091
1092/** @def RT_LOWORD
1093 * Gets the low word (=uint16_t) of something. */
1094#define RT_LOWORD(a) ( (a) & 0xffff )
1095
1096/** @def RT_HIWORD
1097 * Gets the high word (=uint16_t) of a 32-bit something. */
1098#define RT_HIWORD(a) ( (a) >> 16 )
1099
1100/** @def RT_LOBYTE
1101 * Gets the low byte of something. */
1102#define RT_LOBYTE(a) ( (a) & 0xff )
1103
1104/** @def RT_HIBYTE
1105 * Gets the low byte of a 16-bit something. */
1106#define RT_HIBYTE(a) ( (a) >> 8 )
1107
1108/** @def RT_BYTE1
1109 * Gets first byte of something. */
1110#define RT_BYTE1(a) ( (a) & 0xff )
1111
1112/** @def RT_BYTE2
1113 * Gets second byte of something. */
1114#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
1115
1116/** @def RT_BYTE3
1117 * Gets second byte of something. */
1118#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
1119
1120/** @def RT_BYTE4
1121 * Gets fourth byte of something. */
1122#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
1123
1124
1125/** @def RT_MAKE_U64
1126 * Constructs a uint64_t value from two uint32_t values.
1127 */
1128#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
1129
1130/** @def RT_MAKE_U64_FROM_U16
1131 * Constructs a uint64_t value from four uint16_t values.
1132 */
1133#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
1134 ( (uint64_t)((uint16_t)(w3)) << 48 \
1135 | (uint64_t)((uint16_t)(w2)) << 32 \
1136 | (uint32_t)((uint16_t)(w1)) << 16 \
1137 | (uint16_t)(w0) )
1138
1139/** @def RT_MAKE_U64_FROM_U8
1140 * Constructs a uint64_t value from eight uint8_t values.
1141 */
1142#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1143 ( (uint64_t)((uint8_t)(b7)) << 56 \
1144 | (uint64_t)((uint8_t)(b6)) << 48 \
1145 | (uint64_t)((uint8_t)(b5)) << 40 \
1146 | (uint64_t)((uint8_t)(b4)) << 32 \
1147 | (uint32_t)((uint8_t)(b3)) << 24 \
1148 | (uint32_t)((uint8_t)(b2)) << 16 \
1149 | (uint16_t)((uint8_t)(b1)) << 8 \
1150 | (uint8_t)(b0) )
1151
1152/** @def RT_MAKE_U32
1153 * Constructs a uint32_t value from two uint16_t values.
1154 */
1155#define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
1156
1157/** @def RT_MAKE_U32_FROM_U8
1158 * Constructs a uint32_t value from four uint8_t values.
1159 */
1160#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1161 ( (uint32_t)((uint8_t)(b3)) << 24 \
1162 | (uint32_t)((uint8_t)(b2)) << 16 \
1163 | (uint16_t)((uint8_t)(b1)) << 8 \
1164 | (uint8_t)(b0) )
1165
1166/** @def RT_MAKE_U16
1167 * Constructs a uint32_t value from two uint16_t values.
1168 */
1169#define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
1170
1171
1172/** @def RT_BSWAP_U64
1173 * Reverses the byte order of an uint64_t value. */
1174#if 0
1175# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
1176#elif defined(__GNUC__)
1177/** @todo use __builtin_constant_p? */
1178# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1179#else
1180# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1181#endif
1182
1183/** @def RT_BSWAP_U32
1184 * Reverses the byte order of an uint32_t value. */
1185#if 0
1186# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
1187#elif defined(__GNUC__)
1188/** @todo use __builtin_constant_p? */
1189# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1190#else
1191# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1192#endif
1193
1194/** @def RT_BSWAP_U16
1195 * Reverses the byte order of an uint16_t value. */
1196#if 0
1197# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
1198#elif defined(__GNUC__)
1199/** @todo use __builtin_constant_p? */
1200# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1201#else
1202# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1203#endif
1204
1205
1206/** @def RT_BSWAP_U64_C
1207 * Reverses the byte order of an uint64_t constant. */
1208#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
1209
1210/** @def RT_BSWAP_U32_C
1211 * Reverses the byte order of an uint32_t constant. */
1212#define RT_BSWAP_U32_C(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
1213
1214/** @def RT_BSWAP_U16_C
1215 * Reverses the byte order of an uint16_t constant. */
1216#define RT_BSWAP_U16_C(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
1217
1218
1219/** @def RT_H2LE_U64
1220 * Converts an uint64_t value from host to little endian byte order. */
1221#ifdef RT_BIG_ENDIAN
1222# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1223#else
1224# define RT_H2LE_U64(u64) (u64)
1225#endif
1226
1227/** @def RT_H2LE_U64_C
1228 * Converts an uint64_t constant from host to little endian byte order. */
1229#ifdef RT_BIG_ENDIAN
1230# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
1231#else
1232# define RT_H2LE_U64_C(u64) (u64)
1233#endif
1234
1235/** @def RT_H2LE_U32
1236 * Converts an uint32_t value from host to little endian byte order. */
1237#ifdef RT_BIG_ENDIAN
1238# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1239#else
1240# define RT_H2LE_U32(u32) (u32)
1241#endif
1242
1243/** @def RT_H2LE_U32_C
1244 * Converts an uint32_t constant from host to little endian byte order. */
1245#ifdef RT_BIG_ENDIAN
1246# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
1247#else
1248# define RT_H2LE_U32_C(u32) (u32)
1249#endif
1250
1251/** @def RT_H2LE_U16
1252 * Converts an uint16_t value from host to little endian byte order. */
1253#ifdef RT_BIG_ENDIAN
1254# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1255#else
1256# define RT_H2LE_U16(u16) (u16)
1257#endif
1258
1259/** @def RT_H2LE_U16_C
1260 * Converts an uint16_t constant from host to little endian byte order. */
1261#ifdef RT_BIG_ENDIAN
1262# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
1263#else
1264# define RT_H2LE_U16_C(u16) (u16)
1265#endif
1266
1267
1268/** @def RT_LE2H_U64
1269 * Converts an uint64_t value from little endian to host byte order. */
1270#ifdef RT_BIG_ENDIAN
1271# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1272#else
1273# define RT_LE2H_U64(u64) (u64)
1274#endif
1275
1276/** @def RT_LE2H_U64_C
1277 * Converts an uint64_t constant from little endian to host byte order. */
1278#ifdef RT_BIG_ENDIAN
1279# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1280#else
1281# define RT_LE2H_U64_C(u64) (u64)
1282#endif
1283
1284/** @def RT_LE2H_U32
1285 * Converts an uint32_t value from little endian to host byte order. */
1286#ifdef RT_BIG_ENDIAN
1287# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1288#else
1289# define RT_LE2H_U32(u32) (u32)
1290#endif
1291
1292/** @def RT_LE2H_U32_C
1293 * Converts an uint32_t constant from little endian to host byte order. */
1294#ifdef RT_BIG_ENDIAN
1295# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1296#else
1297# define RT_LE2H_U32_C(u32) (u32)
1298#endif
1299
1300/** @def RT_LE2H_U16
1301 * Converts an uint16_t value from little endian to host byte order. */
1302#ifdef RT_BIG_ENDIAN
1303# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
1304#else
1305# define RT_LE2H_U16(u16) (u16)
1306#endif
1307
1308/** @def RT_LE2H_U16_C
1309 * Converts an uint16_t constant from little endian to host byte order. */
1310#ifdef RT_BIG_ENDIAN
1311# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1312#else
1313# define RT_LE2H_U16_C(u16) (u16)
1314#endif
1315
1316
1317/** @def RT_H2BE_U64
1318 * Converts an uint64_t value from host to big endian byte order. */
1319#ifdef RT_BIG_ENDIAN
1320# define RT_H2BE_U64(u64) (u64)
1321#else
1322# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
1323#endif
1324
1325/** @def RT_H2BE_U64_C
1326 * Converts an uint64_t constant from host to big endian byte order. */
1327#ifdef RT_BIG_ENDIAN
1328# define RT_H2BE_U64_C(u64) (u64)
1329#else
1330# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
1331#endif
1332
1333/** @def RT_H2BE_U32
1334 * Converts an uint32_t value from host to big endian byte order. */
1335#ifdef RT_BIG_ENDIAN
1336# define RT_H2BE_U32(u32) (u32)
1337#else
1338# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
1339#endif
1340
1341/** @def RT_H2BE_U32_C
1342 * Converts an uint32_t constant from host to big endian byte order. */
1343#ifdef RT_BIG_ENDIAN
1344# define RT_H2BE_U32_C(u32) (u32)
1345#else
1346# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
1347#endif
1348
1349/** @def RT_H2BE_U16
1350 * Converts an uint16_t value from host to big endian byte order. */
1351#ifdef RT_BIG_ENDIAN
1352# define RT_H2BE_U16(u16) (u16)
1353#else
1354# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
1355#endif
1356
1357/** @def RT_H2BE_U16_C
1358 * Converts an uint16_t constant from host to big endian byte order. */
1359#ifdef RT_BIG_ENDIAN
1360# define RT_H2BE_U16_C(u16) (u16)
1361#else
1362# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
1363#endif
1364
1365/** @def RT_BE2H_U64
1366 * Converts an uint64_t value from big endian to host byte order. */
1367#ifdef RT_BIG_ENDIAN
1368# define RT_BE2H_U64(u64) (u64)
1369#else
1370# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
1371#endif
1372
1373/** @def RT_BE2H_U64
1374 * Converts an uint64_t constant from big endian to host byte order. */
1375#ifdef RT_BIG_ENDIAN
1376# define RT_BE2H_U64_C(u64) (u64)
1377#else
1378# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1379#endif
1380
1381/** @def RT_BE2H_U32
1382 * Converts an uint32_t value from big endian to host byte order. */
1383#ifdef RT_BIG_ENDIAN
1384# define RT_BE2H_U32(u32) (u32)
1385#else
1386# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
1387#endif
1388
1389/** @def RT_BE2H_U32_C
1390 * Converts an uint32_t value from big endian to host byte order. */
1391#ifdef RT_BIG_ENDIAN
1392# define RT_BE2H_U32_C(u32) (u32)
1393#else
1394# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1395#endif
1396
1397/** @def RT_BE2H_U16
1398 * Converts an uint16_t value from big endian to host byte order. */
1399#ifdef RT_BIG_ENDIAN
1400# define RT_BE2H_U16(u16) (u16)
1401#else
1402# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
1403#endif
1404
1405/** @def RT_BE2H_U16_C
1406 * Converts an uint16_t constant from big endian to host byte order. */
1407#ifdef RT_BIG_ENDIAN
1408# define RT_BE2H_U16_C(u16) (u16)
1409#else
1410# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1411#endif
1412
1413
1414/** @def RT_H2N_U64
1415 * Converts an uint64_t value from host to network byte order. */
1416#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
1417
1418/** @def RT_H2N_U64_C
1419 * Converts an uint64_t constant from host to network byte order. */
1420#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
1421
1422/** @def RT_H2N_U32
1423 * Converts an uint32_t value from host to network byte order. */
1424#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1425
1426/** @def RT_H2N_U32_C
1427 * Converts an uint32_t constant from host to network byte order. */
1428#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
1429
1430/** @def RT_H2N_U16
1431 * Converts an uint16_t value from host to network byte order. */
1432#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1433
1434/** @def RT_H2N_U16_C
1435 * Converts an uint16_t constant from host to network byte order. */
1436#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
1437
1438/** @def RT_N2H_U64
1439 * Converts an uint64_t value from network to host byte order. */
1440#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
1441
1442/** @def RT_N2H_U64_C
1443 * Converts an uint64_t constant from network to host byte order. */
1444#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
1445
1446/** @def RT_N2H_U32
1447 * Converts an uint32_t value from network to host byte order. */
1448#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1449
1450/** @def RT_N2H_U32_C
1451 * Converts an uint32_t constant from network to host byte order. */
1452#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
1453
1454/** @def RT_N2H_U16
1455 * Converts an uint16_t value from network to host byte order. */
1456#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1457
1458/** @def RT_N2H_U16_C
1459 * Converts an uint16_t value from network to host byte order. */
1460#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
1461
1462
1463/*
1464 * The BSD sys/param.h + machine/param.h file is a major source of
1465 * namespace pollution. Kill off some of the worse ones unless we're
1466 * compiling kernel code.
1467 */
1468#if defined(RT_OS_DARWIN) \
1469 && !defined(KERNEL) \
1470 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1471 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1472/* sys/param.h: */
1473# undef PSWP
1474# undef PVM
1475# undef PINOD
1476# undef PRIBO
1477# undef PVFS
1478# undef PZERO
1479# undef PSOCK
1480# undef PWAIT
1481# undef PLOCK
1482# undef PPAUSE
1483# undef PUSER
1484# undef PRIMASK
1485# undef MINBUCKET
1486# undef MAXALLOCSAVE
1487# undef FSHIFT
1488# undef FSCALE
1489
1490/* i386/machine.h: */
1491# undef ALIGN
1492# undef ALIGNBYTES
1493# undef DELAY
1494# undef STATUS_WORD
1495# undef USERMODE
1496# undef BASEPRI
1497# undef MSIZE
1498# undef CLSIZE
1499# undef CLSIZELOG2
1500#endif
1501
1502
1503/** @def NULL
1504 * NULL pointer.
1505 */
1506#ifndef NULL
1507# ifdef __cplusplus
1508# define NULL 0
1509# else
1510# define NULL ((void*)0)
1511# endif
1512#endif
1513
1514/** @def NIL_OFFSET
1515 * NIL offset.
1516 * Whenever we use offsets instead of pointers to save space and relocation effort
1517 * NIL_OFFSET shall be used as the equivalent to NULL.
1518 */
1519#define NIL_OFFSET (~0U)
1520
1521/** @def NOREF
1522 * Keeps the compiler from bitching about an unused parameter.
1523 */
1524#define NOREF(var) (void)(var)
1525
1526/** @def Breakpoint
1527 * Emit a debug breakpoint instruction.
1528 *
1529 * Use this for instrumenting a debugging session only!
1530 * No committed code shall use Breakpoint().
1531 */
1532#ifdef __GNUC__
1533# define Breakpoint() __asm__ __volatile__("int $3\n\t")
1534#endif
1535#ifdef _MSC_VER
1536# define Breakpoint() __asm int 3
1537#endif
1538#if defined(__IBMC__) || defined(__IBMCPP__)
1539# define Breakpoint() __interrupt(3)
1540#endif
1541#ifndef Breakpoint
1542# error "This compiler is not supported!"
1543#endif
1544
1545
1546/** @defgroup grp_rt_cdefs_size Size Constants
1547 * (Of course, these are binary computer terms, not SI.)
1548 * @{
1549 */
1550/** 1 K (Kilo) (1 024). */
1551#define _1K 0x00000400
1552/** 4 K (Kilo) (4 096). */
1553#define _4K 0x00001000
1554/** 32 K (Kilo) (32 678). */
1555#define _32K 0x00008000
1556/** 64 K (Kilo) (65 536). */
1557#define _64K 0x00010000
1558/** 128 K (Kilo) (131 072). */
1559#define _128K 0x00020000
1560/** 256 K (Kilo) (262 144). */
1561#define _256K 0x00040000
1562/** 512 K (Kilo) (524 288). */
1563#define _512K 0x00080000
1564/** 1 M (Mega) (1 048 576). */
1565#define _1M 0x00100000
1566/** 2 M (Mega) (2 097 152). */
1567#define _2M 0x00200000
1568/** 4 M (Mega) (4 194 304). */
1569#define _4M 0x00400000
1570/** 1 G (Giga) (1 073 741 824). */
1571#define _1G 0x40000000
1572/** 2 G (Giga) (2 147 483 648). (32-bit) */
1573#define _2G32 0x80000000U
1574/** 2 G (Giga) (2 147 483 648). (64-bit) */
1575#define _2G 0x0000000080000000LL
1576/** 4 G (Giga) (4 294 967 296). */
1577#define _4G 0x0000000100000000LL
1578/** 1 T (Tera) (1 099 511 627 776). */
1579#define _1T 0x0000010000000000LL
1580/** 1 P (Peta) (1 125 899 906 842 624). */
1581#define _1P 0x0004000000000000LL
1582/** 1 E (Exa) (1 152 921 504 606 846 976). */
1583#define _1E 0x1000000000000000LL
1584/** 2 E (Exa) (2 305 843 009 213 693 952). */
1585#define _2E 0x2000000000000000ULL
1586/** @} */
1587
1588
1589/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
1590 * @{ */
1591/** Other format. */
1592#define RT_DBGTYPE_OTHER RT_BIT_32(0)
1593/** Stabs. */
1594#define RT_DBGTYPE_STABS RT_BIT_32(1)
1595/** Debug With Arbitrary Record Format (DWARF). */
1596#define RT_DBGTYPE_DWARF RT_BIT_32(2)
1597/** Microsoft Codeview debug info. */
1598#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
1599/** Watcom debug info. */
1600#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
1601/** IBM High Level Language debug info. */
1602#define RT_DBGTYPE_HLL RT_BIT_32(5)
1603/** Old OS/2 and Windows symbol file. */
1604#define RT_DBGTYPE_SYM RT_BIT_32(6)
1605/** Map file. */
1606#define RT_DBGTYPE_MAP RT_BIT_32(7)
1607/** @} */
1608
1609
1610/** @defgroup grp_rt_cdefs_exetype Executable Image Types
1611 * @{ */
1612/** Some other format. */
1613#define RT_EXETYPE_OTHER RT_BIT_32(0)
1614/** Portable Executable. */
1615#define RT_EXETYPE_PE RT_BIT_32(1)
1616/** Linear eXecutable. */
1617#define RT_EXETYPE_LX RT_BIT_32(2)
1618/** Linear Executable. */
1619#define RT_EXETYPE_LE RT_BIT_32(3)
1620/** New Executable. */
1621#define RT_EXETYPE_NE RT_BIT_32(4)
1622/** DOS Executable (Mark Zbikowski). */
1623#define RT_EXETYPE_MZ RT_BIT_32(5)
1624/** COM Executable. */
1625#define RT_EXETYPE_COM RT_BIT_32(6)
1626/** a.out Executable. */
1627#define RT_EXETYPE_AOUT RT_BIT_32(7)
1628/** Executable and Linkable Format. */
1629#define RT_EXETYPE_ELF RT_BIT_32(8)
1630/** Mach-O Executable (including FAT ones). */
1631#define RT_EXETYPE_MACHO RT_BIT_32(9)
1632/** TE from UEFI. */
1633#define RT_EXETYPE_TE RT_BIT_32(9)
1634/** @} */
1635
1636
1637/** @def VALID_PTR
1638 * Pointer validation macro.
1639 * @param ptr The pointer.
1640 */
1641#if defined(RT_ARCH_AMD64)
1642# ifdef IN_RING3
1643# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1644# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1645 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1646# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
1647# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1648 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1649 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1650# else
1651# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1652 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1653# endif
1654# else /* !IN_RING3 */
1655# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1656 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1657 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1658# endif /* !IN_RING3 */
1659#elif defined(RT_ARCH_X86)
1660# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1661#else
1662# error "Architecture identifier missing / not implemented."
1663#endif
1664
1665/** Old name for RT_VALID_PTR. */
1666#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
1667
1668/** @def RT_VALID_ALIGNED_PTR
1669 * Pointer validation macro that also checks the alignment.
1670 * @param ptr The pointer.
1671 * @param align The alignment, must be a power of two.
1672 */
1673#define RT_VALID_ALIGNED_PTR(ptr, align) \
1674 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
1675 && VALID_PTR(ptr) )
1676
1677
1678/** @def VALID_PHYS32
1679 * 32 bits physical address validation macro.
1680 * @param Phys The RTGCPHYS address.
1681 */
1682#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
1683
1684/** @def N_
1685 * The \#define N_ is used to mark a string for translation. This is usable in
1686 * any part of the code, as it is only used by the tools that create message
1687 * catalogs. This macro is a no-op as far as the compiler and code generation
1688 * is concerned.
1689 *
1690 * If you want to both mark a string for translation and translate it, use _().
1691 */
1692#define N_(s) (s)
1693
1694/** @def _
1695 * The \#define _ is used to mark a string for translation and to translate it
1696 * in one step.
1697 *
1698 * If you want to only mark a string for translation, use N_().
1699 */
1700#define _(s) gettext(s)
1701
1702
1703/** @def __PRETTY_FUNCTION__
1704 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
1705 * for the other compilers.
1706 */
1707#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1708# define __PRETTY_FUNCTION__ __FUNCTION__
1709#endif
1710
1711
1712/** @def RT_STRICT
1713 * The \#define RT_STRICT controls whether or not assertions and other runtime
1714 * checks should be compiled in or not.
1715 *
1716 * If you want assertions which are not subject to compile time options use
1717 * the AssertRelease*() flavors.
1718 */
1719#if !defined(RT_STRICT) && defined(DEBUG)
1720# define RT_STRICT
1721#endif
1722
1723/** Source position. */
1724#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
1725
1726/** Source position declaration. */
1727#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
1728
1729/** Source position arguments. */
1730#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
1731
1732/** @} */
1733
1734
1735/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
1736 * @ingroup grp_rt_cdefs
1737 * @{
1738 */
1739
1740#ifdef __cplusplus
1741
1742/** @def DECLEXPORT_CLASS
1743 * How to declare an exported class. Place this macro after the 'class'
1744 * keyword in the declaration of every class you want to export.
1745 *
1746 * @note It is necessary to use this macro even for inner classes declared
1747 * inside the already exported classes. This is a GCC specific requirement,
1748 * but it seems not to harm other compilers.
1749 */
1750#if defined(_MSC_VER) || defined(RT_OS_OS2)
1751# define DECLEXPORT_CLASS __declspec(dllexport)
1752#elif defined(RT_USE_VISIBILITY_DEFAULT)
1753# define DECLEXPORT_CLASS __attribute__((visibility("default")))
1754#else
1755# define DECLEXPORT_CLASS
1756#endif
1757
1758/** @def DECLIMPORT_CLASS
1759 * How to declare an imported class Place this macro after the 'class'
1760 * keyword in the declaration of every class you want to export.
1761 *
1762 * @note It is necessary to use this macro even for inner classes declared
1763 * inside the already exported classes. This is a GCC specific requirement,
1764 * but it seems not to harm other compilers.
1765 */
1766#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1767# define DECLIMPORT_CLASS __declspec(dllimport)
1768#elif defined(RT_USE_VISIBILITY_DEFAULT)
1769# define DECLIMPORT_CLASS __attribute__((visibility("default")))
1770#else
1771# define DECLIMPORT_CLASS
1772#endif
1773
1774/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
1775 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
1776 * resolver. The following snippet clearly demonstrates the code causing this
1777 * error:
1778 * @code
1779 * class A
1780 * {
1781 * public:
1782 * operator bool() const { return false; }
1783 * operator int*() const { return NULL; }
1784 * };
1785 * int main()
1786 * {
1787 * A a;
1788 * if (!a);
1789 * if (a && 0);
1790 * return 0;
1791 * }
1792 * @endcode
1793 * The code itself seems pretty valid to me and GCC thinks the same.
1794 *
1795 * This macro fixes the compiler error by explicitly overloading implicit
1796 * global operators !, && and || that take the given class instance as one of
1797 * their arguments.
1798 *
1799 * The best is to use this macro right after the class declaration.
1800 *
1801 * @note The macro expands to nothing for compilers other than MSVC.
1802 *
1803 * @param Cls Class to apply the workaround to
1804 */
1805#if defined(_MSC_VER)
1806# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
1807 inline bool operator! (const Cls &that) { return !bool (that); } \
1808 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
1809 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
1810 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
1811 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
1812#else
1813# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
1814#endif
1815
1816/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
1817 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
1818 *
1819 * @param Tpl Name of the template class to apply the workaround to
1820 * @param ArgsDecl arguments of the template, as declared in |<>| after the
1821 * |template| keyword, including |<>|
1822 * @param Args arguments of the template, as specified in |<>| after the
1823 * template class name when using the, including |<>|
1824 *
1825 * Example:
1826 * @code
1827 * // template class declaration
1828 * template <class C>
1829 * class Foo { ... };
1830 * // applied workaround
1831 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
1832 * @endcode
1833 */
1834#if defined(_MSC_VER)
1835# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
1836 template ArgsDecl \
1837 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
1838 template ArgsDecl \
1839 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
1840 template ArgsDecl \
1841 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
1842 template ArgsDecl \
1843 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
1844 template ArgsDecl \
1845 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
1846#else
1847# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
1848#endif
1849
1850
1851/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
1852 * Declares the copy constructor and the assignment operation as inlined no-ops
1853 * (non-existent functions) for the given class. Use this macro inside the
1854 * private section if you want to effectively disable these operations for your
1855 * class.
1856 *
1857 * @param Cls class name to declare for
1858 */
1859
1860#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
1861 inline Cls (const Cls &); \
1862 inline Cls &operator= (const Cls &);
1863
1864
1865/** @def DECLARE_CLS_NEW_DELETE_NOOP
1866 * Declares the new and delete operations as no-ops (non-existent functions)
1867 * for the given class. Use this macro inside the private section if you want
1868 * to effectively limit creating class instances on the stack only.
1869 *
1870 * @note The destructor of the given class must not be virtual, otherwise a
1871 * compile time error will occur. Note that this is not a drawback: having
1872 * the virtual destructor for a stack-based class is absolutely useless
1873 * (the real class of the stack-based instance is always known to the compiler
1874 * at compile time, so it will always call the correct destructor).
1875 *
1876 * @param Cls class name to declare for
1877 */
1878#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
1879 inline static void *operator new (size_t); \
1880 inline static void operator delete (void *);
1881
1882#endif /* defined(__cplusplus) */
1883
1884/** @} */
1885
1886#endif
1887
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