所以这可能是一个很长的镜头,但有没有办法将C或C++文件作为脚本运行?我试过了:
#!/usr/bin/gcc main.c -o main; ./main
int main(){ return 0; }
Run Code Online (Sandbox Code Playgroud)
但它说:
./main.c:1:2: error: invalid preprocessing directive #!
Run Code Online (Sandbox Code Playgroud) 我正在尝试为在Win XP上运行的C++程序编写一个byteswap例程.我正在使用Visual Studio 2008编译.这就是我想出的:
int byteswap(int v) // This is good
{
return _byteswap_ulong(v);
}
double byteswap(double v) // This doesn't work for some values
{
union { // This trick is first used in Quake2 source I believe :D
__int64 i;
double d;
} conv;
conv.d = v;
conv.i = _byteswap_uint64(conv.i);
return conv.d;
}
Run Code Online (Sandbox Code Playgroud)
还有一个测试功能:
void testit() {
double a, b, c;
CString str;
for (a = -100; a < 100; a += 0.01) {
b = byteswap(a);
c …Run Code Online (Sandbox Code Playgroud) 我想使用 RGBA 值表示 32 位数字,使用联合生成该数字的值是否可移植?考虑这个 C 代码;
union pixel {
uint32_t value;
uint8_t RGBA[4];
};
Run Code Online (Sandbox Code Playgroud)
这编译得很好,并且我喜欢使用它而不是一堆函数。但这安全吗?