_Imaginary Optional pure imaginary types
_Imaginary Optional pure imaginary types
C99's optional _Imaginary is often unsupported. Portable code uses double _Complex, checks implementation macros, and provides a complex fallback.
| Category | Type specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C99 |
📝 Syntax
double _Imaginary iz = 4.0 * I; /* Supported by few implementations */
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
complex fallback = 4
⚠️ Warning _Imaginary is optional. The example uses it when __STDC_IEC_559_COMPLEX__ and _Imaginary_I are available, otherwise falling back to double _Complex. The listed complex fallback = 4 output is GCC 10.2's default branch because it lacks _Imaginary support.
🏷️ Related type specifiers
📚 Related Tutorials
❓ FAQ
QWhat is the difference between _Imaginary and _Complex?
A_Imaginary denotes a pure imaginary type, while _Complex denotes a complex type with both real and imaginary parts. For everyday complex arithmetic, _Complex is generally used because it is more widely supported.
QWhy does the _Imaginary example run _Complex fallback code by default?
ACommon implementations, including GCC, do not provide pure imaginary types, so using _Imaginary unconditionally would fail to compile. Conditional compilation retains the demonstration for supporting platforms while allowing others to run the complete example.
QHow can I detect whether a compiler supports _Imaginary?
ANo single convention covers every C99 implementation. Combine its documentation with conditional checks for capability markers such as __STDC_IEC_559_COMPLEX__ and _Imaginary_I, and verify the result with the target compiler.