pastebin - collaborative debugging tool
rovema.kpaste.net RSS


c99_strict_aliasing_union/c99_strict_aliasing_union1.c
Posted by Anonymous on Wed 25th Aug 2021 11:11
raw | new post

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4.  
  5. bool is_negative(float x) {
  6.         union {
  7.                 signed int si;
  8.                 unsigned int ui;
  9.                 double xx;
  10.                 float d;
  11.                 char bb[16384];
  12.         } my_union = { .d = x };
  13.         return my_union.ui & 0x80000000;
  14. }
  15.  
  16. int main(int ac, char *av[])
  17. {
  18.         float x;
  19.        
  20.         puts("#start.");
  21.        
  22.         x = -1;
  23.         (void)printf("is_negative=%d\n", (int)is_negative(x));
  24.         x = 1;
  25.         (void)printf("is_negative=%d\n", (int)is_negative(x));
  26.  
  27.         puts("#done.");
  28.         return EXIT_SUCCESS;
  29. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at