Tech /

Unordered Sets





edit SideBar

Unordered Sets
  • Using complex to define unordered sets?

Example

Source

     1  #include <stdio.h>
     2  #include <complex.h>
     3  
     4  typedef complex int unordered_i; // non-standard!
     5  typedef complex double unordered;
     6  
     7  #define S1 ((unordered)(1*I))  // GCC-extension!
     8  static const unordered S2 = (2*I);  // GCC-extension!
     9  static unordered state = S2; // non-const initializer!
    10  
    11  
    12  int main(void)
    13  {
    14      if (state != S2) return 1;
    15      if (state > S1) return 2; // Compiler error - our objective!
    16  
    17      return 0;
    18  }
    19  

GCC

$ c99 --version
gcc (Debian 4.3.2-1.1) 4.3.2
$ c99 -std=c99 --pedantic -o unordered unordered.c 
unordered.c:4: warning: ISO C does not support complex integer types
unordered.c:8:32: warning: imaginary constants are a GCC extension
unordered.c:9: error: initializer element is not constant
unordered.c:15:17: warning: imaginary constants are a GCC extension
unordered.c: In function main:
unordered.c:15: error: invalid operands to binary > (have unordered and complex double)
Recent Changes (All) | Edit SideBar Page last modified on 13 January 2010, at 12:49 PM UTC Edit Page | Page History
Powered by PmWiki