c_ByteOrder

Overview

Types and Definitions

definitions

cBYTE_ORDER_

#define cBYTE_ORDER_

Defines the c_ByteOrder values.

c_ByteOrder

enum c_ByteOrder {
   c_BigEndian = 0,
   c_LittleEndian = 1,
};
type enum c_ByteOrder c_ByteOrder;

Enum type to represent the endiness of a system, file format or protocol.

Functions

swap

swap_two_bytes_c_

#define swap_two_bytes_c_( Data )

Macro function that returns a two byte long value with a changed byte order.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/c_ByteOrder.h"
#include "clingo/type/cByte.h"
#include "clingo/type/uint16.h"

int main( void )
{
   init_tap_c_();

   uint16_t const origVal = 0x12cd;
   uint16_t swapVal = swap_two_bytes_c_( origVal );

   cByte const* origPtr = (void const*)&origVal;
   cByte const* swapPtr = (void const*)&swapVal;

   expect_c_( origVal == 0x12cd );

   expect_c_( origPtr[ 0 ] == swapPtr[ 1 ] );
   expect_c_( origPtr[ 1 ] == swapPtr[ 0 ] );

   return finish_tap_c_();
}

swap_four_bytes_c_

#define swap_four_bytes_c_( Data )

Macro function that returns a four byte long value with a changed byte order.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/c_ByteOrder.h"
#include "clingo/type/cByte.h"
#include "clingo/type/uint32.h"

int main( void )
{
   init_tap_c_();

   uint32_t const origVal = 0xa1b2c3d4;
   uint32_t swapVal = swap_four_bytes_c_( origVal );

   cByte const* origPtr = (void const*)&origVal;
   cByte const* swapPtr = (void const*)&swapVal;

   expect_c_( origVal == 0xa1b2c3d4 );

   expect_c_( origPtr[ 0 ] == swapPtr[ 3 ] );
   expect_c_( origPtr[ 1 ] == swapPtr[ 2 ] );
   expect_c_( origPtr[ 2 ] == swapPtr[ 1 ] );
   expect_c_( origPtr[ 3 ] == swapPtr[ 0 ] );

   return finish_tap_c_();
}

swap_eight_bytes_c_

#define swap_eight_bytes_c_( Data )

Macro function that returns a eight byte long value with a changed byte order.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/c_ByteOrder.h"
#include "clingo/type/cByte.h"
#include "clingo/type/uint64.h"

int main( void )
{
   init_tap_c_();

   uint64_t const origVal = 0xabcdef0123456789;
   uint64_t swapVal = swap_eight_bytes_c_( origVal );

   cByte const* origPtr = (void const*)&origVal;
   cByte const* swapPtr = (void const*)&swapVal;

   expect_c_( origVal == 0xabcdef0123456789 );

   expect_c_( origPtr[ 0 ] == swapPtr[ 7 ] );
   expect_c_( origPtr[ 1 ] == swapPtr[ 6 ] );
   expect_c_( origPtr[ 2 ] == swapPtr[ 5 ] );
   expect_c_( origPtr[ 3 ] == swapPtr[ 4 ] );

   expect_c_( origPtr[ 4 ] == swapPtr[ 3 ] );
   expect_c_( origPtr[ 5 ] == swapPtr[ 2 ] );
   expect_c_( origPtr[ 6 ] == swapPtr[ 1 ] );
   expect_c_( origPtr[ 7 ] == swapPtr[ 0 ] );

   return finish_tap_c_();
}

util

system_order_c

c_ByteOrder system_order_c();

The function returns the byte order of the system.

system_order_is_c

bool system_order_is_c( c_ByteOrder order );

Function to check the byte order of the system.

stringify_byte_order_c

char const* stringify_byte_order_c( c_ByteOrder order );

Returns the string representation of a value.

Example
#include "clingo/lang/expect.h"
#include "clingo/type/c_ByteOrder.h"

int main( void )
{
   init_tap_c_();

   c_ByteOrder val;

   val = c_BigEndian;
   expect_eq_c_( strcmp( "c_BigEndian", stringify_byte_order_c( val ) ) );

   val = c_LittleEndian;
   expect_eq_c_( strcmp( "c_LittleEndian", stringify_byte_order_c( val ) ) );

   return finish_tap_c_();
}