.
T unsigned char, T. , . T , ():
int value = 568;
unsigned char store[sizeof( int )];
memcpy( store , &value , sizeof( int ) );
int other;
memcpy( &other , store , sizeof( int ) );
assert( other == value ),
(ab), . : , , - char .
implementation.c
#include "implementation.h"
struct invisible
{
int element1;
char element2
float element3;
void** element4;
};
_Static_assert( sizeof( struct invisible ) <= VISIBLE_SIZE );
struct visible New( void )
{
struct invisible i = { 1 , '2' , 3.0F , NULL };
struct visible v = { 0 };
memcpy( &v , &i , sizeof(i) );
return v;
}
void Next( struct visible* v )
{
struct invisible i = { 0 };
memcpy( &i , &v , sizeof(i) );
i.element1++;
const int next = i.element;
memcpy( &v , &i , sizeof(i) );
return next;
}
implementation.h
#define VISIBLE_SIZE 24
struct visible
{
unsigned char[VISIBLE_SIZE];
};
struct visible New( void );
int Next( struct visible* v );
user.c
#include "implementation.h"
void Func( void )
{
struct visible v = New();
while( 1 )
{
const int next = Next( &v );
if( next == 10 )
{
break;
}
printf( "%d\n" , next );
}
}
element1. .