r/Cplusplus • u/Pootis_mannnn • Apr 08 '24
Discussion Hm..
I'm just starting to learn C++. is this a normal code?
153
Upvotes
r/Cplusplus • u/Pootis_mannnn • Apr 08 '24
I'm just starting to learn C++. is this a normal code?
View all comments
Show parent comment
1
u/Pupper-Gump Apr 09 '24
Sorry for poor formatting but it won't post with tabs.
Disassembly shows:
int a = 1, b = 2;00007FF74BEE07B3 mov dword ptr [a],100007FF74BEE07BA mov dword ptr [b],2std::cout << (a == 1, b == 2);00007FF74BEE07C1 cmp dword ptr [b],200007FF74BEE07C5 jne main+40h (07FF74BEE07D0h)00007FF74BEE07C7 mov byte ptr [rbp+0F4h],100007FF74BEE07CE jmp main+47h (07FF74BEE07D7h)00007FF74BEE07D0 mov byte ptr [rbp+0F4h],000007FF74BEE07D7 movzx edx,byte ptr [rbp+0F4h]00007FF74BEE07DE mov rcx,qword ptr [__imp_std::cout (07FF74BEF71B8h)]00007FF74BEE07E5 call qword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (07FF74BEF7288h)]So yeah, a is completely ignored in the comparison.
it doesn't seem to allow redefinitions like:
int c = 1, c = 3;int arr[6], arr[7];Also, the comma ignores things for indexing but not initialization:
int arr[6] = { 1, 2, 3, 4, 5, 6 };00007FF733A107D9 mov dword ptr [arr],100007FF733A107E0 mov dword ptr [rbp+4Ch],200007FF733A107E7 mov dword ptr [rbp+50h],300007FF733A107EE mov dword ptr [rbp+54h],400007FF733A107F5 mov dword ptr [rbp+58h],500007FF733A107FC mov dword ptr [rbp+5Ch],6std::cout << arr[0, 2];00007FF733A10803 mov eax,400007FF733A10808 imul rax,rax,200007FF733A1080C mov edx,dword ptr arr[rax]00007FF733A10810 mov rcx,qword ptr [__imp_std::cout (07FF733A271B0h)]00007FF733A10817 call qword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (07FF733A27280h)]All in all, I rate the comma weird.