在我的程序中,我统计他们想要的文件并发送数据.stat的字段struct都是特殊类型:
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number …Run Code Online (Sandbox Code Playgroud) 我有一个代码库,旨在在没有警告的情况下进行编译,并在多种架构上运行而不会出现任何故障,所有 x86:MSDOS、Windows 32 控制台模式、Windows 32 GUI 模式、Linux 32 和 Linux 64。
\n\n在添加对 Linux 64 的支持之前,这很容易。几乎所有数据都被声明为intBYTE、WORD 和 DWORD 的类型定义:
typedef unsigned char BYTE;\ntypedef unsigned short WORD;\ntypedef unsigned long DWORD;\nRun Code Online (Sandbox Code Playgroud)\n\n添加 64 位 gcc 支持后,DWORD 需要进行一些调整才能保持 32 位值,因为它表示存储的数据:
\n\n// to compile DWORDs as 32 bits on 64-bit machines:\n#if __x86_64__\n typedef unsigned int DWORD;\n#else\n typedef unsigned long DWORD;\n#endif\nRun Code Online (Sandbox Code Playgroud)\n\n这在所有环境下都运行良好:
\n\nDWORD data;\nprintf ("%lu", data);\nRun Code Online (Sandbox Code Playgroud)\n\n但是,gcc -Wall现在抱怨格式转换:
warning: format \xe2\x80\x98%ld\xe2\x80\x99 expects argument of …Run Code Online (Sandbox Code Playgroud) 对不起,如果标题令人困惑.这是我的结构:
struct l_list{
int number;
char *name;
double value;
struct l_list *next;
};
typedef struct l_list *PhoneBook;
Run Code Online (Sandbox Code Playgroud)
主功能:
int main(void){
printf("%u\n", sizeof(struct l_list));
PhoneBook person1;
printf("%u\n", sizeof(*person1));
printf("%u\n", sizeof(PhoneBook));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
20
20
4
据我所知,PhoneBook它显示的是4个字节,因为它只是指针的大小,但是如何从?找到实际结构的大小typedef PhoneBook?
我想要为应用程序ID使用某种常量(所以我可以在printf中使用它).
我有这个:
#define _APPID_ "Hello World!"
Run Code Online (Sandbox Code Playgroud)
然后是简单的printf,将其调用为%s(字符串).它说出来了:
simple.cpp:32: error: cannot convert ‘_IO_FILE*’ to ‘const char*’ for argument ‘1’ to ‘int printf(const char*, ...)’
我将使用什么来定义要在printf中使用的应用程序ID?我试过了:
static const char _APPID_[] = "Hello World"`
Run Code Online (Sandbox Code Playgroud)
但它没有用,我认为同样的错误.