回答編集履歴
3
追記
test
CHANGED
@@ -115,3 +115,97 @@
|
|
115
115
|
usr ~/Project/test/teratail %
|
116
116
|
|
117
117
|
```
|
118
|
+
|
119
|
+
もとのソースのアセンブル結果(clang)
|
120
|
+
|
121
|
+
```asm
|
122
|
+
|
123
|
+
.text
|
124
|
+
|
125
|
+
.file "t.c"
|
126
|
+
|
127
|
+
.globl main # -- Begin function main
|
128
|
+
|
129
|
+
.p2align 4, 0x90
|
130
|
+
|
131
|
+
.type main,@function
|
132
|
+
|
133
|
+
main: # @main
|
134
|
+
|
135
|
+
.cfi_startproc
|
136
|
+
|
137
|
+
# %bb.0:
|
138
|
+
|
139
|
+
subq $24, %rsp
|
140
|
+
|
141
|
+
.cfi_def_cfa_offset 32
|
142
|
+
|
143
|
+
movl $100, 12(%rsp)
|
144
|
+
|
145
|
+
movl $.L.str, %eax
|
146
|
+
|
147
|
+
movb %al, 11(%rsp)
|
148
|
+
|
149
|
+
movl $.L.str.1, %edi
|
150
|
+
|
151
|
+
movl $100, %esi
|
152
|
+
|
153
|
+
xorl %eax, %eax
|
154
|
+
|
155
|
+
callq printf
|
156
|
+
|
157
|
+
leaq 8(%rsp), %rdi
|
158
|
+
|
159
|
+
callq puts
|
160
|
+
|
161
|
+
xorl %eax, %eax
|
162
|
+
|
163
|
+
addq $24, %rsp
|
164
|
+
|
165
|
+
.cfi_def_cfa_offset 8
|
166
|
+
|
167
|
+
retq
|
168
|
+
|
169
|
+
.Lfunc_end0:
|
170
|
+
|
171
|
+
.size main, .Lfunc_end0-main
|
172
|
+
|
173
|
+
.cfi_endproc
|
174
|
+
|
175
|
+
# -- End function
|
176
|
+
|
177
|
+
.type .L.str,@object # @.str
|
178
|
+
|
179
|
+
.section .rodata.str1.1,"aMS",@progbits,1
|
180
|
+
|
181
|
+
.L.str:
|
182
|
+
|
183
|
+
.asciz "OK"
|
184
|
+
|
185
|
+
.size .L.str, 3
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
.type .L.str.1,@object # @.str.1
|
190
|
+
|
191
|
+
.L.str.1:
|
192
|
+
|
193
|
+
.asciz "%d\n"
|
194
|
+
|
195
|
+
.size .L.str.1, 4
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
.ident "clang version 8.0.0 (trunk 350063)"
|
202
|
+
|
203
|
+
.section ".note.GNU-stack","",@progbits
|
204
|
+
|
205
|
+
.addrsig
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
「movb %al, 11(%rsp)」これを見ると、うまい具合wにいけてますね。puts()呼んでる^^;
|
210
|
+
|
211
|
+
こちらの結果は、「100以外何も表示されない」です。たぶん'\0'が有った。
|
2
ソース追記
test
CHANGED
@@ -15,3 +15,103 @@
|
|
15
15
|
```
|
16
16
|
|
17
17
|
でもいいけど・・・
|
18
|
+
|
19
|
+
「追記」
|
20
|
+
|
21
|
+
ソース改変しました。
|
22
|
+
|
23
|
+
```c
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
|
27
|
+
//#include <stdlib.h>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
typedef struct {
|
32
|
+
|
33
|
+
char name[3];
|
34
|
+
|
35
|
+
int number;
|
36
|
+
|
37
|
+
double average;
|
38
|
+
|
39
|
+
} ABC;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
typedef struct {
|
44
|
+
|
45
|
+
char ID[3];
|
46
|
+
|
47
|
+
ABC data;
|
48
|
+
|
49
|
+
int at;
|
50
|
+
|
51
|
+
} DEF;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
int main(void)
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
ABC abc;
|
60
|
+
|
61
|
+
ABC *pabc;
|
62
|
+
|
63
|
+
pabc = &abc;
|
64
|
+
|
65
|
+
abc.number = 100;
|
66
|
+
|
67
|
+
abc.name[0] = 'O';
|
68
|
+
|
69
|
+
abc.name[1] = 'K';
|
70
|
+
|
71
|
+
abc.name[2] = '\0';
|
72
|
+
|
73
|
+
// abc.name[3] = "OK";
|
74
|
+
|
75
|
+
DEF b[] = { { "t2", { "x6", 200, 21.2 }, 12 },
|
76
|
+
|
77
|
+
{ "t3", { "x7", 300, 13.3 }, 13 },
|
78
|
+
|
79
|
+
{ "t4", { "xA", 400, 77.1 }, 14 } };
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
printf("%d\n", pabc->number);
|
84
|
+
|
85
|
+
printf("%s\n", pabc->name);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
return 0;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
bが使われていない!ワーニングは出ますが・・・
|
96
|
+
|
97
|
+
```text
|
98
|
+
|
99
|
+
usr ~/Project/test/teratail % cc t176513.c
|
100
|
+
|
101
|
+
t176513.c:26:9: warning: unused variable 'b' [-Wunused-variable]
|
102
|
+
|
103
|
+
DEF b[] = { { "t2", { "x6", 200, 21.2 }, 12 },
|
104
|
+
|
105
|
+
^
|
106
|
+
|
107
|
+
1 warning generated.
|
108
|
+
|
109
|
+
usr ~/Project/test/teratail % ./a.out
|
110
|
+
|
111
|
+
100
|
112
|
+
|
113
|
+
OK
|
114
|
+
|
115
|
+
usr ~/Project/test/teratail %
|
116
|
+
|
117
|
+
```
|
1
追記
test
CHANGED
@@ -2,4 +2,16 @@
|
|
2
2
|
|
3
3
|
C言語は文字列の代入は出来ません。strcpy()を使いましょう。
|
4
4
|
|
5
|
-
・・・添え字はおかしい
|
5
|
+
・・・添え字はおかしい(3番めはない)
|
6
|
+
|
7
|
+
```c
|
8
|
+
|
9
|
+
abc.name[0] = 'O';
|
10
|
+
|
11
|
+
abc.name[1] = 'K';
|
12
|
+
|
13
|
+
abc.name[2] = '\0';
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
でもいいけど・・・
|