这是我测试复制struct的代码.
1 #include <stdio.h>
2 #include <string.h>
3
4 typedef struct emp_struct {
5 char *name;
6 int employee_no;
7 float salary,
8 tax_to_date;
9 } Employee;
10
11 typedef Employee Database[10];
12
13 Database people = {
14 {"Fred", 10, 10000, 3000},
15 {"Jim", 9, 12000, 3100.5},
16 {"Fred", 13, 1000000, 30},
17 {"Mary", 11, 170000, 4000},
18 {"Judith", 45, 130000, 50000},
19 {"Nigel", 10, 5000, 1200},
20 {"Trevor", 10, 20000, 6000},
21 {"Karen", 10, 120000, 34000},
22 {"Marianne", …Run Code Online (Sandbox Code Playgroud) 当我调试我的次要移植程序时,我对类型转换差异有疑问.
这是我的来源(下面):
1 #include <time.h>
2 #include <stdio.h>
3
7 int main () {
8 clock_t now; //unsigned long
9 struct tm * mac_time; // const long
10 char *time_str;
11 now = time (NULL);
12 mac_time = localtime((const long *)&now);
13 // localtime ( const long <- unsigned long)
13 time_str = asctime(mac_time);
14 printf("Now : %s\n",time_str);
15 return 0;
16 }
Run Code Online (Sandbox Code Playgroud)
首先,它正常工作,现在没有错误.但我对类型铸造差异有疑问.
在第12行中,由于发生了类型转换警告,我更改了调试的值类型.
但有什么区别
12 mac_time = localtime((const long *)&now);
Run Code Online (Sandbox Code Playgroud)
和
12 mac_time = localtime(&(const long *)now);
Run Code Online (Sandbox Code Playgroud)
我认为彼此之间没有区别,因为这只是'铸造价值的地址和'价值的地址铸造'. …
当我结束我的程序时,我发现了'glibc detected'这样的消息.但是,我不知道这是错误还是警告,否则..有人可以解释一下这条消息的含义以及我该怎么办?
