Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 小端宏_C_Macros_Header Files_Endianness - Fatal编程技术网

C 小端宏

C 小端宏,c,macros,header-files,endianness,C,Macros,Header Files,Endianness,因此,我有一个新的和令人兴奋的问题,我非常希望得到回答。所以我在写一个文件压缩程序,基本上是一个tar,老实说,代码运行得很好。我现在遇到的问题是项目需要的一个附加功能。我们需要能够生成二进制文件,就好像它们是在一台小小的endian机器上生成的一样。我已经创建了一个头文件,我已经将它包含在我的代码中,可以为我进行位交换。其内容如下: #ifndef MYLIB_H #define MYLIB_H #define BITS_PER_BYTE 8 #define true 1 #define f

因此,我有一个新的和令人兴奋的问题,我非常希望得到回答。所以我在写一个文件压缩程序,基本上是一个tar,老实说,代码运行得很好。我现在遇到的问题是项目需要的一个附加功能。我们需要能够生成二进制文件,就好像它们是在一台小小的endian机器上生成的一样。我已经创建了一个头文件,我已经将它包含在我的代码中,可以为我进行位交换。其内容如下:

#ifndef MYLIB_H
#define MYLIB_H

#define BITS_PER_BYTE 8
#define true 1
#define false 0

typedef unsigned char uchar;
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short ushort;

#ifdef LITTLE_ENDIAN

#define SwapULong(val) (val << 24 | (val << 8 & 0xFF0000) | (val >> 8 & 0xFF00) | val >> 24 & 0xFF)
#define SwapUShort(val) (val << BITS_PER_BYTE | val >> BITS_PER_BYTE)

#else

#define SwapULong(val) (val)
#define SwapUShort(val) (val)

#endif

#endif
变成

./compress line #: __extension__ : command not found
直到终端输出的最后几行显示

./compress line 86: syntax error near unexpected '}' token
./compress line 86: __extension__ typedef struct { int __val[2]; } __fsid_t;
你知道是什么原因让我这么做的吗


任何帮助都将不胜感激

您需要包括
endian.h
标题。

第86行是什么?你能把它和周围的线条加到你的问题上吗?哇。真不敢相信我竟然忘了。但它解决了它!谢谢您。
./compress line 86: syntax error near unexpected '}' token
./compress line 86: __extension__ typedef struct { int __val[2]; } __fsid_t;