Я сейчас компилирую это в Ubuntu и когда я компилирую эту программу
#include <stdio.h>
struct vector { float x,y,z; };
struct vector V_new2(x,y,z){
struct vector thenew;
thenew.x = x;
thenew.y = y;
thenew.z = z;
return thenew;
}
float* V_new1(x,y,z){
float thenew[3];
thenew[0] = x;
thenew[1] = y;
thenew[2] = z;
return thenew;
}
int main()
{
float *v1 = V_new1(5,6,7);
struct vector v2 = V_new2(1,2,3);
printf("v1 : (%f,%f,%f)\n",v1[0],v1[1],v1[2]);
printf("v2 : (%f,%f,%f)\n",v2.x, v2.y, v2.z);
return 0;
}
Я получаю эти сообщения в терминале, а в другом компиляторе я просто получаю ошибку сегментации после добавления кодов в основную функцию.
w.c: In function ‘V_new2’:
w.c:5:15: warning: type of ‘x’ defaults to ‘int’ [-Wimplicit-int]
struct vector V_new2(x,y,z){
^~~~~~
w.c:5:15: warning: type of ‘y’ defaults to ‘int’ [-Wimplicit-int]
w.c:5:15: warning: type of ‘z’ defaults to ‘int’ [-Wimplicit-int]
w.c: In function ‘V_new1’:
w.c:13:8: warning: type of ‘x’ defaults to ‘int’ [-Wimplicit-int]
float* V_new1(x,y,z){
^~~~~~
w.c:13:8: warning: type of ‘y’ defaults to ‘int’ [-Wimplicit-int]
w.c:13:8: warning: type of ‘z’ defaults to ‘int’ [-Wimplicit-int]
w.c:18:12: warning: function returns address of local variable [-Wreturn-local-addr]
return thenew;
Как это исправить?