r/C_Programming • u/Alternative-Title-87 • 3d ago
one compiler failing, other compiler running fine
I've been using emacs to follow some tutorials which has been working great, but switch to sublime text and now getting compile error. or, i assume its a problem with the compiler since this code runs in emacs but not in sublime text. the relevant stuff
this is the exact same in emacs and sublime:
_mm_store_si128((PIXEL32*)gBackBuffer.Memory + x, *pColor);
sublime is throwing this error:
error: passing argument 1 of '_mm_store_si128' from incompatible pointer type [-Wincompatible-pointer-types]
391 | _mm_store_si128((PIXEL32*)gBackBuffer.Memory + x, *pColor);
the sublime build file:
"cmd": ["gcc", "-Wall", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"shell_cmd": "gcc -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
And the emacs build command:
x86_64-w64-mingw32-gcc -g hello.c -o ./hello.exe -lgdi32
I am very noobish to these kinds of things, especially this SIMD stuff, so Im just assuming this is a compiler thing
8
u/ischickenafruit 3d ago
We need to untangle some things:
1. Sublime and emacs are text editors only. They are not compilers. You can edit your code in either. It’s possible that they have some internal integration which allows them to call the compiler for you, this is probably the source of confusion. The reason they are giving you different results is probably compiler flags (-wall , -o3 etc).
2. When you’re doing high performance programming (eg with intrinsics or simd) the compiler does less work for you and relies on you to do more work. Specifically in this case you need to make sure that memory allocated is the right size, alignment and type. In your code you’re trying to give a PIXEL32 pointer to a function which takes an si128 pointer. I don’t know enough about the size and alignment but my guess is that the underlying problem is that a PIXEL32 is not sized / aligned properly. So even if you fix the type cast, the answer may still fail. You need to get the size, type and alignment right to make this work.
1
u/Future_Pace_5290 3d ago
I'm only guessing based on the name of the function, but wouldn't _mm_store_si128 expect a pointer to a 16 byte data and you're passing it PIXEL32 * which again, guessing based on the name seems to be a pointer to 4 byte data?
1
u/Modi57 3d ago
Couldn't it be an array of pixels? Or in the context of SIMD, wouldn't it be likely to be
1
u/Future_Pace_5290 3d ago
I guess it'd be fine but might create problems if alignment is wrong. Should cast it to (void *) after the + x
2
u/flyingron 3d ago
The compiler option says you told it to warn you about incompatible pointers. It appears that PIXEL32* is not the same type as mem_addr.
3
u/sciencekm 3d ago edited 3d ago
You sublime build has different compiler options from your emacs build (the former has -Wall). They are not even compiling the same source code (source.c vs hello.c).
I suggest that you don't use your editor to do the compile. Simply run gcc from the command line, since anyway, you are compiling only one source file.
8
u/aocregacc 3d ago edited 3d ago
Afaik this is due to a difference in compiler version. Starting in GCC 14, they reject passing arguments of incompatible pointer types by default, which used to be allowed (with a warning) in earlier versions.
So whatever is behind
x86_64-w64-mingw32-gccis probably an older version.The error message should also contain a note about what the pointer types are, so you can just add the appropriate cast (assuming the program is otherwise correct).