Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Test bitfields with unnamed union
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//clang 3.7.0 #include <iostream> typedef struct bitfield { unsigned int a:16; unsigned int b:17; union u { unsigned int c:4; unsigned int d:32; }U; }bfield; typedef struct bitfield2 { unsigned int a:16; unsigned int b:17; union { unsigned int c:4; unsigned int d:32; }; }bfield2; int main() { std::cout << "Test bitfields1\n" << sizeof(bfield) << "\n"; std::cout << "Test bitfields2\n" << sizeof(bfield2) << "\n"; static volatile bfield y; y.a=0x1234; y.b = 0x1FF55; y.U.d = 0x5a5a5a5a; std::cout << std::hex << y.U.d << "\n"; static volatile bfield2 x; x.a=0x1234; x.b = 0x1FF55; x.d = 0x5a5a5a5a; std::cout << std::hex << x.d << "\n"; }
clang++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.52 sec, absolute running time: 0.13 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0,66 sec
fork mode
|
history
|
discussion