Messages in this thread | | | Date | Wed, 20 May 1998 18:04:29 -0400 (EDT) | From | Robert Minichino <> | Subject | Re: 'C' Operators precedence |
| |
On Wed, 20 May 1998, Richard B. Johnson wrote:
> On Wed, 20 May 1998, Matthew Kirkwood wrote: > > > On Wed, 20 May 1998, Richard B. Johnson wrote: > > > > And this _without_ optimisation. gcc is right to do this; if a function > > clobbers registers, then let it do so when the variables don't contain > > anything interersting anyway. > > > > Your point was..? > > > > Sigh. It has nothing to do with clobbering registers. It has to do with > the fact that the function(s) and/or macros, anything that closes (), will > all be 'evaluated' first. To evaluate a function, requires that any > parameters passed to the function be stabilized by a sequence-point, and > the function be called. To evaluate a macro, requires only that it be > expanded as text. However, the () for passed parameters to a macro, if > it exists, requires that the contents of () be evaluated before the > macro is expanded, because () has the highest presedence of any 'C' > operator. > > #include <stdio.h> > > static int a, b, c, d, e; > static int f() > { > return a; > } > int main() > { > b = 1; > c = 2; > d = 3; > e = 4; > printf("%d\n", f() + b + c + d + e ); > printf("%d\n", b + f() + c + d + e ); > printf("%d\n", b + c + f() + d + e ); > printf("%d\n", b + c + d + e + f() ); > return 0; > > }
I just compiled that under Watcom C/C++ 11.0a with -otexan. I attached the disassembly. It doesn't call f at the same place all the time. Go figure. So much for proof-by-compiler output. I think it's time for this thread to die.
- Robert Minichino
Module: C:\winnt\profiles\administrator\desktop\asdf.c GROUP: 'DGROUP' CONST,CONST2,_DATA,_BSS
Segment: _TEXT PARA USE32 0000012F bytes
#include <stdio.h>
static int a, b, c, d, e; static int f() 0000 f_: 0000 53 push ebx 0001 51 push ecx 0002 52 push edx 0003 56 push esi 0004 57 push edi 0005 55 push ebp 0006 89 E5 mov ebp,esp 0008 81 EC 04 00 00 00 sub esp,0x00000004
{ return a; 000E L$1: 000E A1 00 00 00 00 mov eax,_a 0013 89 45 FC mov -0x4[ebp],eax
} 0016 8B 45 FC mov eax,-0x4[ebp] 0019 L$2: 0019 89 EC mov esp,ebp 001B 5D pop ebp 001C 5F pop edi 001D 5E pop esi 001E 5A pop edx 001F 59 pop ecx 0020 5B pop ebx 0021 C3 ret 0022 L$3: 0022 8D 80 00 00 00 00 lea eax,[eax] 0028 8D 92 00 00 00 00 lea edx,[edx] 002E 8B C0 mov eax,eax
int main()
Routine Size: 48 bytes, Routine Base: _TEXT + 0000
0030 main_: 0030 53 push ebx 0031 51 push ecx 0032 52 push edx 0033 56 push esi 0034 57 push edi 0035 55 push ebp 0036 89 E5 mov ebp,esp 0038 81 EC 04 00 00 00 sub esp,0x00000004
{ b = 1; 003E L$4: 003E C7 05 00 00 00 00 01 00 00 00 mov dword ptr _b,0x00000001
c = 2; 0048 C7 05 00 00 00 00 02 00 00 00 mov dword ptr _c,0x00000002
d = 3; 0052 C7 05 00 00 00 00 03 00 00 00 mov dword ptr _d,0x00000003
e = 4; 005C C7 05 00 00 00 00 04 00 00 00 mov dword ptr _e,0x00000004
printf("%d\n", f() + b + c + d + e ); 0066 E8 00 00 00 00 call f_ 006B 03 05 00 00 00 00 add eax,_b 0071 03 05 00 00 00 00 add eax,_c 0077 03 05 00 00 00 00 add eax,_d 007D 03 05 00 00 00 00 add eax,_e 0083 50 push eax 0084 B8 00 00 00 00 mov eax,offset L$7 0089 50 push eax 008A E8 00 00 00 00 call printf_ 008F 83 C4 08 add esp,0x00000008
printf("%d\n", b + f() + c + d + e ); 0092 E8 00 00 00 00 call f_ 0097 03 05 00 00 00 00 add eax,_b 009D 03 05 00 00 00 00 add eax,_c 00A3 03 05 00 00 00 00 add eax,_d 00A9 03 05 00 00 00 00 add eax,_e 00AF 50 push eax 00B0 B8 00 00 00 00 mov eax,offset L$7 00B5 50 push eax 00B6 E8 00 00 00 00 call printf_ 00BB 83 C4 08 add esp,0x00000008
printf("%d\n", b + c + f() + d + e ); 00BE A1 00 00 00 00 mov eax,_b 00C3 03 05 00 00 00 00 add eax,_c 00C9 89 C2 mov edx,eax 00CB E8 00 00 00 00 call f_ 00D0 01 D0 add eax,edx 00D2 03 05 00 00 00 00 add eax,_d 00D8 03 05 00 00 00 00 add eax,_e 00DE 50 push eax 00DF B8 00 00 00 00 mov eax,offset L$7 00E4 50 push eax 00E5 E8 00 00 00 00 call printf_ 00EA 83 C4 08 add esp,0x00000008
printf("%d\n", b + c + d + e + f() ); 00ED A1 00 00 00 00 mov eax,_b 00F2 03 05 00 00 00 00 add eax,_c 00F8 03 05 00 00 00 00 add eax,_d 00FE 8B 15 00 00 00 00 mov edx,_e 0104 01 C2 add edx,eax 0106 E8 00 00 00 00 call f_ 010B 01 D0 add eax,edx 010D 50 push eax 010E B8 00 00 00 00 mov eax,offset L$7 0113 50 push eax 0114 E8 00 00 00 00 call printf_ 0119 83 C4 08 add esp,0x00000008
return 0; 011C C7 45 FC 00 00 00 00 mov dword ptr -0x4[ebp],0x00000000
} 0123 8B 45 FC mov eax,-0x4[ebp] 0126 L$5: 0126 89 EC mov esp,ebp 0128 5D pop ebp 0129 5F pop edi 012A 5E pop esi 012B 5A pop edx 012C 59 pop ecx 012D 5B pop ebx 012E C3 ret 012F L$6:
Routine Size: 255 bytes, Routine Base: _TEXT + 0030
No disassembly errors
Segment: CONST DWORD USE32 00000004 bytes 0000 L$7: 0000 25 64 0A 00 %d..
Segment: _BSS DWORD USE32 00000014 bytes 0000 _a: 0004 _b: 0008 _c: 000C _d: 0010 _e:
BSS Size: 20 bytes
Segment: .debug_info BYTE USE32 00000236 bytes 0000 L$8: 0000 32 02 00 00 02 00 2..... 0006 00 00 00 00 DD L$10 000A 04 07 35 02 00 00 ..5... 0010 00 00 00 00 DD f_ 0014 2F 01 00 00 DD L$6 0018 43 3A 5C 77 69 6E 6E 74 5C 70 72 6F 66 69 6C 65 C:\winnt\profile 0028 73 5C 61 64 6D 69 6E 69 73 74 72 61 74 6F 72 5C s\administrator\ 0038 64 65 73 6B 74 6F 70 5C 61 73 64 66 2E 63 00 desktop\asdf.c. 0047 00 00 00 00 DD L$9 004B 01 00 56 31 2E 30 20 57 41 54 43 4F 4D 00 00 ..V1.0 WATCOM.. 005A 00 00 00 00 DD L$11 005E 00 00 00 00 01 ..... 0063 04 00 00 00 DD L$12 0067 09 63 68 61 72 00 08 01 09 73 69 67 6E 65 64 20 .char....signed 0077 63 68 61 72 00 06 01 09 75 6E 73 69 67 6E 65 64 char....unsigned 0087 20 63 68 61 72 00 08 01 09 73 68 6F 72 74 00 05 char....short.. 0097 02 09 75 6E 73 69 67 6E 65 64 20 73 68 6F 72 74 ..unsigned short 00A7 00 07 02 09 69 6E 74 00 05 04 09 75 6E 73 69 67 ....int....unsig 00B7 6E 65 64 20 69 6E 74 00 07 04 09 6C 6F 6E 67 00 ned int....long. 00C7 05 04 09 75 6E 73 69 67 6E 65 64 20 6C 6F 6E 67 ...unsigned long 00D7 00 07 04 09 5F 5F 69 6E 74 36 34 00 05 08 09 75 ....__int64....u 00E7 6E 73 69 67 6E 65 64 20 5F 5F 69 6E 74 36 34 00 nsigned __int64. 00F7 07 08 0B 01 66 70 6F 73 5F 74 00 C1 00 00 00 0F ....fpos_t...... 0107 67 00 00 00 18 01 06 01 00 00 0B 01 5F 5F 76 61 g...........__va 0117 5F 6C 69 73 74 00 0B 01 00 00 0B 01 73 69 7A 65 _list.......size 0127 5F 74 00 B1 00 00 00 0B 01 77 63 68 61 72 5F 74 _t.......wchar_t 0137 00 98 00 00 00 0B 01 77 63 74 79 70 65 5F 74 00 .......wctype_t. 0147 2E 01 00 00 0B 01 77 69 6E 74 5F 74 00 2E 01 00 ......wint_t.... 0157 00 D2 01 01 00 00 61 00 05 03 ......a... 0161 00 00 00 00 DD _a 0165 AA 00 00 00 D2 01 01 00 00 62 00 05 03 .........b... 0172 00 00 00 00 DD _b 0176 AA 00 00 00 D2 01 01 00 00 63 00 05 03 .........c... 0183 00 00 00 00 DD _c 0187 AA 00 00 00 D2 01 01 00 00 64 00 05 03 .........d... 0194 00 00 00 00 DD _d 0198 AA 00 00 00 D2 01 01 00 00 65 00 05 03 .........e... 01A5 00 00 00 00 DD _e 01A9 AA 00 00 00 86 01 EF 01 00 00 01 AA 00 00 00 0E ................ 01B9 66 00 00 00 01 01 00 00 02 91 18 f.......... 01C4 00 00 00 00 DD f_ 01C8 22 00 00 00 DD L$3 01CC 00 D2 01 01 00 01 2E 72 65 74 75 72 6E 00 01 50 .......return..P 01DC AA 00 00 00 66 EE 01 00 00 ....f.... 01E5 0E 00 00 00 DD L$1 01E9 19 00 00 00 DD L$2 01ED 00 00 86 01 34 02 00 00 01 AA 00 00 00 0E 6D 61 ....4.........ma 01FD 69 6E 00 01 00 01 01 00 00 02 91 18 in.......... 0209 30 00 00 00 DD main_ 020D 2F 01 00 00 DD L$6 0211 00 D2 01 01 00 01 2E 72 65 74 75 72 6E 00 01 50 .......return..P 0221 AA 00 00 00 66 33 02 00 00 ....f3... 022A 3E 00 00 00 DD L$4 022E 26 01 00 00 DD L$5 0232 00 00 00 00 ....
Segment: .debug_pubnames BYTE USE32 0000001B bytes 0000 17 00 00 00 02 00 ...... 0006 00 00 00 00 DD L$8 000A 2F 01 00 00 EF 01 00 00 6D 61 69 6E 00 00 00 00 /.......main.... 001A 00 .
Segment: .debug_aranges BYTE USE32 0000002C bytes 0000 28 00 00 00 02 00 (..... 0006 00 00 00 00 DD L$8 000A 04 00 .. 000C 00 00 00 00 DD f_ 0010 2F 01 00 00 /... 0014 00 00 00 00 DD L$7 0018 04 00 00 00 .... 001C 00 00 00 00 DD _a 0020 14 00 00 00 00 00 00 00 00 00 00 00 ............
Segment: .debug_line BYTE USE32 0000006C bytes 0000 L$9: 0000 68 00 00 00 02 00 10 00 00 00 01 00 FF 04 0A 00 h............... 0010 01 01 01 01 00 00 00 00 00 00 00 33 03 43 3A 5C ...........3.C:\ 0020 77 69 6E 6E 74 5C 70 72 6F 66 69 6C 65 73 5C 61 winnt\profiles\a 0030 64 6D 69 6E 69 73 74 72 61 74 6F 72 5C 64 65 73 dministrator\des 0040 6B 74 6F 70 5C 61 73 64 66 2E 63 00 00 00 00 00 ktop\asdf.c..... 0050 05 02 .. 0052 00 00 00 00 DD f_ 0056 06 05 01 03 03 01 45 2C 74 45 34 34 34 34 BC BC ......E,tE4444.. 0066 C8 C8 28 00 01 01 ..(...
Segment: .debug_abbrev BYTE USE32 00000088 bytes 0000 L$10: 0000 07 11 01 01 13 11 01 12 01 03 08 10 06 13 0F 1B ................ 0010 08 25 08 42 0F 43 06 35 10 82 41 0B 83 41 06 00 .%.B.C.5..A..A.. 0020 00 09 24 00 03 08 3E 0B 0B 0B 00 00 0B 16 00 32 ..$...>........2 0030 0B 03 08 49 13 00 00 0F 0F 00 49 13 00 00 18 01 ...I......I..... 0040 00 37 0F 49 13 00 00 D2 01 34 00 32 0B 3F 0C 34 .7.I.....4.2.?.4 0050 0C 03 08 02 0A 49 13 00 00 86 01 2E 01 01 13 32 .....I.........2 0060 0B 49 13 2C 0F 03 08 3F 0C 20 0B 36 0B 27 0C 4C .I.,...?. .6.'.L 0070 0B 34 0C 2A 0A 11 01 12 01 33 0B 00 00 66 0B 01 .4.*.....3...f.. 0080 01 13 11 01 12 01 00 00 ........
Segment: .debug_macinfo BYTE USE32 00000001 bytes 0000 L$11: 0000 00 .
Segment: .WATCOM_references BYTE USE32 00000004 bytes 0000 00 00 00 00 .... 0004 L$12:
| |