Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #define STRUCT_NAME( type, count ) arr_##type##_##count##_s
- #define TYPE_NAME( type, count ) arr_##type##_##count##_t
- #define X_TYPES \
- X( int, 1 ) \
- X( int, 2 ) \
- X( int, 3 ) \
- X( double, 4 )
- #define X( type, count ) \
- typedef struct STRUCT_NAME( type, count ) \
- { \
- type arr[count]; \
- } TYPE_NAME( type, count );
- X_TYPES
- #undef X
- #define X( type, count ) \
- type sum_##type##_##count( TYPE_NAME( type, count ) val ) \
- { \
- int sum = 0, i; \
- for ( i = 0; i < count; i++ ) \
- { \
- sum += val.arr[i]; \
- } \
- return sum; \
- }
- X_TYPES
- #undef X
- int main( int argc, char** argv )
- {
- TYPE_NAME( int, 3 ) x = { { 1, 2, 3 } };
- printf( "%i\n", sum_int_3( x ) );
- TYPE_NAME( double, 4 ) y = { { 1.0, 2.5, 3.0, 4.5 } };
- printf( "%lf\n", sum_double_4( y ) );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement