JacksonAllan / Verstable

A versatile, performance-oriented generic hash table library for C.
MIT License
78 stars 9 forks source link

Compile Error on gcc 4.8.5 #3

Closed sfd1v closed 9 months ago

sfd1v commented 9 months ago
#include <stdio.h>

#define NAME int_int_map
#define KEY_TY int 
#define VAL_TY int  
#include "verstable.h"

int main(int argc, char const *argv[])
{
    int_int_map htable;
    vt_init(&htable);

    return 0;
}
[root@DESKTOP-OAKHD5F src]# gcc -std=c11 main.c 
In file included from main.c:6:0:
verstable.h: In function ‘int_int_map_evict’:
verstable.h:894:3: warning: implicit declaration of function ‘_Generic’ [-Wimplicit-function-declaration]
   size_t home_bucket = HASH_FN( table->buckets[ bucket ].key ) & ( table->bucket_count - 1 );
   ^
verstable.h:763:44: error: expected expression before ‘char’
 #define HASH_FN _Generic( ( KEY_TY ){ 0 }, char *: vt_hash_string, default: vt_hash_integer )
                                            ^
verstable.h:894:24: note: in expansion of macro ‘HASH_FN’
   size_t home_bucket = HASH_FN( table->buckets[ bucket ].key ) & ( table->bucket_count - 1 );
                        ^
verstable.h: In function ‘int_int_map_insert_raw’:
verstable.h:763:44: error: expected expression before ‘char’
 #define HASH_FN _Generic( ( KEY_TY ){ 0 }, char *: vt_hash_string, default: vt_hash_integer )
                                            ^
verstable.h:966:19: note: in expansion of macro ‘HASH_FN’
   uint64_t hash = HASH_FN( key );
                   ^
verstable.h:772:44: error: expected expression before ‘char’
 #define CMPR_FN _Generic( ( KEY_TY ){ 0 }, char *: vt_cmpr_string, default: vt_cmpr_integer )
                                            ^
verstable.h:1007:9: note: in expansion of macro ‘CMPR_FN’
         CMPR_FN( table->buckets[ bucket ].key, key )
         ^
verstable.h: In function ‘int_int_map_get’:
verstable.h:763:44: error: expected expression before ‘char’
 #define HASH_FN _Generic( ( KEY_TY ){ 0 }, char *: vt_hash_string, default: vt_hash_integer )
                                            ^
verstable.h:1209:19: note: in expansion of macro ‘HASH_FN’
   uint64_t hash = HASH_FN( key );
                   ^
verstable.h:772:44: error: expected expression before ‘char’
 #define CMPR_FN _Generic( ( KEY_TY ){ 0 }, char *: vt_cmpr_string, default: vt_cmpr_integer )
                                            ^
verstable.h:1221:74: note: in expansion of macro ‘CMPR_FN’
     if( ( table->metadata[ bucket ] & VT_HASH_FRAG_MASK ) == hashfrag && CMPR_FN( table->buckets[ bucket ].key, key ) )
                                                                          ^
verstable.h: In function ‘int_int_map_erase_itr_raw’:
verstable.h:763:44: error: expected expression before ‘char’
 #define HASH_FN _Generic( ( KEY_TY ){ 0 }, char *: vt_hash_string, default: vt_hash_integer )
                                            ^
verstable.h:1277:25: note: in expansion of macro ‘HASH_FN’
       itr.home_bucket = HASH_FN( table->buckets[ itr_bucket ].key ) & ( table->bucket_count - 1 );
                         ^
In file included from main.c:6:0:
main.c: In function ‘main’:
verstable.h:579:65: error: expected expression before ‘vt_table_0000’
 #define vt_init( table ) _Generic( *( table ) VT_GENERIC_SLOTS( vt_table_, vt_init_ ) )( table )
                                                                 ^
verstable.h:405:25: note: in definition of macro ‘VT_CAT_’
 #define VT_CAT_( a, b ) a##b
                         ^
verstable.h:544:40: note: in expansion of macro ‘VT_CAT’
 #define VT_GENERIC_SLOT( ty, fn, n ) , VT_CAT( ty, n ): VT_CAT( fn, n )
                                        ^
verstable.h:546:35: note: in expansion of macro ‘VT_GENERIC_SLOT’
 #define VT_R1_1( ty, fn, d3, d2 ) VT_GENERIC_SLOT( ty, fn, VT_CAT_4( 0, d3, d2, 0 ) )
                                   ^
verstable.h:405:25: note: in expansion of macro ‘VT_R1_1’
 #define VT_CAT_( a, b ) a##b
                         ^
verstable.h:579:47: note: in expansion of macro ‘VT_GENERIC_SLOTS’
 #define vt_init( table ) _Generic( *( table ) VT_GENERIC_SLOTS( vt_table_, vt_init_ ) )( table )
                                               ^
main.c:13:5: note: in expansion of macro ‘vt_init’
     vt_init(&flow_table);
     ^
[root@DESKTOP-OAKHD5F src]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
JacksonAllan commented 9 months ago

You can set -std=c11 on GCC 4.8.5, but full support for C11—including _Generic—only came in 4.9.0. Hence, you have two options: