VirtualBox

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

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

-DLINUX not needed anymore

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