A macro is preprocessor definition that is processed prior to compilation. All occurances of a macro within your C++ source code are replaced with the macro definition, much like an automated search-and-replace-all operation. If the macro's definition is a function with one or more arguments, then the function is inline expanded within your code, replacing the defined arguments with the arguments that were passed to the macro. However, macro functions are not type safe and cannot be debugged because they only exist in your source code; the compiler only sees the intermediate code emitted by the preprocessor, at which point all macro definitions will no longer exist. To address this problem, C++ also supports the concept of template functions, which not only eliminates any unwanted inline expansion (resulting in smaller code), but also ensures that all calls to the function are type safe and can be debugged in the normal way. That said, macro functions, when used appropriately, can greatly simplify your code and can achieve things that would be difficult if not impossible to achieve with C++ alone. The ability to use code fragments via a macro is one such possibility. However, when combined with preprocessor directives such as #ifdef DEBUG, macros can also be used to provide useful and powerful debugging routines that only exist in debug code, compiling to no code in release builds. This cannot be achieved with C++ alone.
A macro function is a macro definition that represents a typeless function definition. All occurrences of the macro symbol within the source code are expanded with the macro definition, replacing the parameters within the macro definition with the arguments or expressions supplied by the source code.
Since macro expansion is a precompiler operation, the compiler has no access to the original macro, and the intermediate source will contain expanded code that doesn't exist in the source. This means that any side-effects resulting from an incorrect usage of the macro cannot be identified within the source. In other words, the compiler may or may not be able to identify a problem resulting from macro expansion, but even if it can, it cannot tell you how to resolve it since it is compiling the expanded code, not the original source code.
The biggest problem with macro functions (and macros in general) is that they are typeless, while C++ is a strongly-typed language. Since the compiler cannot debug a macro, this can often result in untraceable side-effects. For instance, when passing an expression as an argument to a macro function, it is important that the macro function evaluate the parameter before processing it, otherwise the expression will be evaluated during processing, which typically results in multiple evaluations with undefined behaviour.
Another problem with macro functions is that they are always inline expanded, even in debug code. While inline expansion reduces the need to make an otherwise time consuming function call, the increased code size could easily have the opposite effect, slowing overall performance. The compiler's optimisers are in a much better position to decide if inline expansion is warranted.
Function templates are always the preferred option to macro functions, as they are type safe, can be easily debugged, and adhere to the compiler's inline expansion optimiser. Macro functions should only be utilised if they would result in cleaner code than would otherwise be possible with C++ alone (simplifying an otherwise complex C++ routine), or where C++ alone is incapable of achieving a desired effect. Macro functions are also useful when it comes to debugging source code, such us providing user-defined trace and assertion routines, as the macro function can be collapsed to no code in release builds far more easily than with C++ code. However, macro functions are more difficult to write and maintain, and impossible to debug. Keep in mind that macros and C++ are essentially completely separate languages, and that there is no interpreter. The compiler cannot help you so all responsibility for both defining and using macros correctly lies with you, the programmer.
Macro (in C language) is a way to map a certain input sequence to a sequence of character. The mapping is performed in the pre-processor stage.
Macro can take parameters.
Don't write, it is already written, google for 'cpp'.
A typedef is a compiler macro. A reference is a pointer, usually implemented with transparent syntax. They have no relationship between each other.
The NULL macro is an implementation-defined macro. It is used to symbolise the zero address (0x0) in C programs and older C++ programs. It is not type safe, but is the conventional method of assigning the zero address to a pointer variable. C++11 introduced the type-safe nullptr data type.
I assume you mean using lower case letters. By convention, C and C++ standard libraries use lower-case naming conventions. This makes it easy to identify functions and types that belong to the standard library. When defining your own types, a leading capital is preferred. All capitals typically denotes a macro definition.
C: there are no methods in C. C++: no.
#define biggest (a) > (b) && (a) > (c) ? (a) : (b) > (c) ? (b) : (c)
Don't write, it is already written, google for 'cpp'.
C++ programs won't compile if they contain compiler errors. The compiler will tell you precisely where the error is, and the type of error, unless the error is in a macro. The compiler cannot see macro definitions because they are inline expanded prior to compilation.
A typedef is a compiler macro. A reference is a pointer, usually implemented with transparent syntax. They have no relationship between each other.
C+i+g=?
55
ultra
The NULL macro is an implementation-defined macro. It is used to symbolise the zero address (0x0) in C programs and older C++ programs. It is not type safe, but is the conventional method of assigning the zero address to a pointer variable. C++11 introduced the type-safe nullptr data type.
b+b+b+c+c+c+c =3b+4c
c + c + 2c + c + c = 6c
b + b + b + c + c + c + c = 3b + 4c
4c