Hi,

I am linking s7 with a C++ library and the compiler now balks on
the new s7_complex definition:

        ./s7.h:351:14: warning: 's7_complex_vector_ref' has C-linkage 
specified, but returns user-defined type 's7_complex' (aka 'complex<double>') 
which is incompatible with C [-Wreturn-type-c-linkage]
          s7_complex s7_complex_vector_ref(s7_pointer vec, s7_int index);
                     ^
        ./s7.h:352:14: warning: 's7_complex_vector_set' has C-linkage 
specified, but returns user-defined type 's7_complex' (aka 'complex<double>') 
which is incompatible with C [-Wreturn-type-c-linkage]
          s7_complex s7_complex_vector_set(s7_pointer vec, s7_int index, 
s7_complex value);
                     ^

This is "solved" by the attached patch which changes the return
type of the offending functions to a s7_complex*. This makes the
compiler happy but obviously this is not the right solution.

I know it's only a warning but a warning is a sign that the compiler
vendor is going to quietly make it undefined behaviour soon and I
don't know C++ well enough to rewrite the macros around the s7_complex
definition into something the compiler would like.

Matthew

--- ../s7/s7.c	Sat Oct  5 22:10:09 2024
+++ s7.c	Wed Oct  9 23:07:48 2024
@@ -41357,8 +41359,8 @@
 s7_double s7_float_vector_set(s7_pointer vec, s7_int index, s7_double value) {float_vector(vec, index) = value; return(value);}
 
 s7_complex *s7_complex_vector_elements(s7_pointer vec) {return(complex_vector_complexs(vec));}
-s7_complex s7_complex_vector_ref(s7_pointer vec, s7_int index) {return(complex_vector(vec, index));}
-s7_complex s7_complex_vector_set(s7_pointer vec, s7_int index, s7_complex value) {complex_vector(vec, index) = value; return(value);}
+s7_complex *s7_complex_vector_ref(s7_pointer vec, s7_int index) {return&(complex_vector(vec, index));}
+s7_complex *s7_complex_vector_set(s7_pointer vec, s7_int index, s7_complex value) {complex_vector(vec, index) = value; return&(complex_vector(vec, index));}
 
 s7_int s7_vector_dimensions(s7_pointer vec, s7_int *dims, s7_int dims_size)
 {

--- ../s7/s7.h	Sat Oct  5 22:10:09 2024
+++ s7.h	Wed Oct  9 23:07:58 2024
@@ -348,8 +348,8 @@
   s7_pointer s7_make_complex_vector(s7_scheme *sc, s7_int len, s7_int dims, s7_int *dim_info);
   s7_pointer s7_make_complex_vector_wrapper(s7_scheme *sc, s7_int len, s7_complex *data, s7_int dims, s7_int *dim_info, bool free_data);
   s7_complex *s7_complex_vector_elements(s7_pointer vec);
-  s7_complex s7_complex_vector_ref(s7_pointer vec, s7_int index);
-  s7_complex s7_complex_vector_set(s7_pointer vec, s7_int index, s7_complex value);
+  s7_complex *s7_complex_vector_ref(s7_pointer vec, s7_int index);
+  s7_complex *s7_complex_vector_set(s7_pointer vec, s7_int index, s7_complex value);
 #endif
 
 void s7_vector_fill(s7_scheme *sc, s7_pointer vec, s7_pointer obj);                   /* (vector-fill! vec obj) */
_______________________________________________
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist

Reply via email to