Thread: DIfference between , and ;

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    84

    DIfference between , and ;

    Hi,

    I had this minor question -

    What is the difference between using a , and ; to seperate expressions ?

    for example-lets say i have a rectangle class and it has a constructor with 4 arguments -

    Code:
    IntRect(int left, int right , int bottom, int top) { l = left; r = right; b = bottom; t = top; }
    What is the difference if I write it like this ->
    Code:
    IntRect(int left, int right , int bottom, int top) { l = left, r = right, b = bottom, t = top; }
    I know a ; is used to finish an expression, but what is the internal(assembly level) difference between , and ; if there is any ?

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    here is the source code spinet which i wrote to give your answer i can't find any difference strange in assembly with objdump

    Code:
    #include <stdio.h>
    
    int set_value_1(const int a, const int b) {
      int x = 0;
      int y = 0;
      x = a, y = b;
      printf("%d %d\n", x, y);
    }
    
    int set_value_2(const int a, const int b) {
      int x = 0;
      int y = 0;
      x = a;
      y = b;
      printf("%d %d\n", x, y);
    }
    
    int main() {
      set_value_1(10, 20);
      set_value_1(10, 20);
    
      return 0;
    }

    Objdump of exe

    08048374 <set_value_1>:
    8048374: 55 push %ebp
    8048375: 89 e5 mov %esp,%ebp
    8048377: 83 ec 28 sub $0x28,%esp
    804837a: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
    8048381: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
    8048388: 8b 45 08 mov 0x8(%ebp),%eax
    804838b: 89 45 f8 mov %eax,-0x8(%ebp)
    804838e: 8b 45 0c mov 0xc(%ebp),%eax
    8048391: 89 45 fc mov %eax,-0x4(%ebp)
    8048394: 8b 45 fc mov -0x4(%ebp),%eax
    8048397: 89 44 24 08 mov %eax,0x8(%esp)
    804839b: 8b 45 f8 mov -0x8(%ebp),%eax
    804839e: 89 44 24 04 mov %eax,0x4(%esp)
    80483a2: c7 04 24 00 85 04 08 movl $0x8048500,(%esp)
    80483a9: e8 2a ff ff ff call 80482d8 <printf@plt>
    80483ae: c9 leave
    80483af: c3 ret

    080483b0 <set_value_2>:
    80483b0: 55 push %ebp
    80483b1: 89 e5 mov %esp,%ebp
    80483b3: 83 ec 28 sub $0x28,%esp
    80483b6: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
    80483bd: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
    80483c4: 8b 45 08 mov 0x8(%ebp),%eax
    80483c7: 89 45 f8 mov %eax,-0x8(%ebp)
    80483ca: 8b 45 0c mov 0xc(%ebp),%eax
    80483cd: 89 45 fc mov %eax,-0x4(%ebp)
    80483d0: 8b 45 fc mov -0x4(%ebp),%eax
    80483d3: 89 44 24 08 mov %eax,0x8(%esp)
    80483d7: 8b 45 f8 mov -0x8(%ebp),%eax
    80483da: 89 44 24 04 mov %eax,0x4(%esp)
    80483de: c7 04 24 00 85 04 08 movl $0x8048500,(%esp)
    80483e5: e8 ee fe ff ff call 80482d8 <printf@plt>
    80483ea: c9 leave
    80483eb: c3 ret


    The whole assembly instruction set is here

    test: file format elf32-i386


    Disassembly of section .init:

    08048278 <_init>:
    8048278: 55 push %ebp
    8048279: 89 e5 mov %esp,%ebp
    804827b: 53 push %ebx
    804827c: 83 ec 04 sub $0x4,%esp
    804827f: e8 00 00 00 00 call 8048284 <_init+0xc>
    8048284: 5b pop %ebx
    8048285: 81 c3 d8 13 00 00 add $0x13d8,%ebx
    804828b: 8b 93 fc ff ff ff mov -0x4(%ebx),%edx
    8048291: 85 d2 test %edx,%edx
    8048293: 74 05 je 804829a <_init+0x22>
    8048295: e8 1e 00 00 00 call 80482b8 <__gmon_start__@plt>
    804829a: e8 b1 00 00 00 call 8048350 <frame_dummy>
    804829f: e8 0c 02 00 00 call 80484b0 <__do_global_ctors_aux>
    80482a4: 58 pop %eax
    80482a5: 5b pop %ebx
    80482a6: c9 leave
    80482a7: c3 ret

    Disassembly of section .plt:

    080482a8 <__gmon_start__@plt-0x10>:
    80482a8: ff 35 60 96 04 08 pushl 0x8049660
    80482ae: ff 25 64 96 04 08 jmp *0x8049664
    80482b4: 00 00 add %al,(%eax)
    ...

    080482b8 <__gmon_start__@plt>:
    80482b8: ff 25 68 96 04 08 jmp *0x8049668
    80482be: 68 00 00 00 00 push $0x0
    80482c3: e9 e0 ff ff ff jmp 80482a8 <_init+0x30>

    080482c8 <__libc_start_main@plt>:
    80482c8: ff 25 6c 96 04 08 jmp *0x804966c
    80482ce: 68 08 00 00 00 push $0x8
    80482d3: e9 d0 ff ff ff jmp 80482a8 <_init+0x30>

    080482d8 <printf@plt>:
    80482d8: ff 25 70 96 04 08 jmp *0x8049670
    80482de: 68 10 00 00 00 push $0x10
    80482e3: e9 c0 ff ff ff jmp 80482a8 <_init+0x30>

    Disassembly of section .text:

    080482f0 <_start>:
    80482f0: 31 ed xor %ebp,%ebp
    80482f2: 5e pop %esi
    80482f3: 89 e1 mov %esp,%ecx
    80482f5: 83 e4 f0 and $0xfffffff0,%esp
    80482f8: 50 push %eax
    80482f9: 54 push %esp
    80482fa: 52 push %edx
    80482fb: 68 40 84 04 08 push $0x8048440
    8048300: 68 50 84 04 08 push $0x8048450
    8048305: 51 push %ecx
    8048306: 56 push %esi
    8048307: 68 ec 83 04 08 push $0x80483ec
    804830c: e8 b7 ff ff ff call 80482c8 <__libc_start_main@plt>
    8048311: f4 hlt
    8048312: 90 nop
    8048313: 90 nop
    8048314: 90 nop
    8048315: 90 nop
    8048316: 90 nop
    8048317: 90 nop
    8048318: 90 nop
    8048319: 90 nop
    804831a: 90 nop
    804831b: 90 nop
    804831c: 90 nop
    804831d: 90 nop
    804831e: 90 nop
    804831f: 90 nop

    08048320 <__do_global_dtors_aux>:
    8048320: 55 push %ebp
    8048321: 89 e5 mov %esp,%ebp
    8048323: 83 ec 08 sub $0x8,%esp
    8048326: 80 3d 80 96 04 08 00 cmpb $0x0,0x8049680
    804832d: 74 0c je 804833b <__do_global_dtors_aux+0x1b>
    804832f: eb 1c jmp 804834d <__do_global_dtors_aux+0x2d>
    8048331: 83 c0 04 add $0x4,%eax
    8048334: a3 7c 96 04 08 mov %eax,0x804967c
    8048339: ff d2 call *%edx
    804833b: a1 7c 96 04 08 mov 0x804967c,%eax
    8048340: 8b 10 mov (%eax),%edx
    8048342: 85 d2 test %edx,%edx
    8048344: 75 eb jne 8048331 <__do_global_dtors_aux+0x11>
    8048346: c6 05 80 96 04 08 01 movb $0x1,0x8049680
    804834d: c9 leave
    804834e: c3 ret
    804834f: 90 nop

    08048350 <frame_dummy>:
    8048350: 55 push %ebp
    8048351: 89 e5 mov %esp,%ebp
    8048353: 83 ec 08 sub $0x8,%esp
    8048356: a1 8c 95 04 08 mov 0x804958c,%eax
    804835b: 85 c0 test %eax,%eax
    804835d: 74 12 je 8048371 <frame_dummy+0x21>
    804835f: b8 00 00 00 00 mov $0x0,%eax
    8048364: 85 c0 test %eax,%eax
    8048366: 74 09 je 8048371 <frame_dummy+0x21>
    8048368: c7 04 24 8c 95 04 08 movl $0x804958c,(%esp)
    804836f: ff d0 call *%eax
    8048371: c9 leave
    8048372: c3 ret
    8048373: 90 nop

    08048374 <set_value_1>:
    8048374: 55 push %ebp
    8048375: 89 e5 mov %esp,%ebp
    8048377: 83 ec 28 sub $0x28,%esp
    804837a: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
    8048381: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
    8048388: 8b 45 08 mov 0x8(%ebp),%eax
    804838b: 89 45 f8 mov %eax,-0x8(%ebp)
    804838e: 8b 45 0c mov 0xc(%ebp),%eax
    8048391: 89 45 fc mov %eax,-0x4(%ebp)
    8048394: 8b 45 fc mov -0x4(%ebp),%eax
    8048397: 89 44 24 08 mov %eax,0x8(%esp)
    804839b: 8b 45 f8 mov -0x8(%ebp),%eax
    804839e: 89 44 24 04 mov %eax,0x4(%esp)
    80483a2: c7 04 24 00 85 04 08 movl $0x8048500,(%esp)
    80483a9: e8 2a ff ff ff call 80482d8 <printf@plt>
    80483ae: c9 leave
    80483af: c3 ret

    080483b0 <set_value_2>:
    80483b0: 55 push %ebp
    80483b1: 89 e5 mov %esp,%ebp
    80483b3: 83 ec 28 sub $0x28,%esp
    80483b6: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
    80483bd: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
    80483c4: 8b 45 08 mov 0x8(%ebp),%eax
    80483c7: 89 45 f8 mov %eax,-0x8(%ebp)
    80483ca: 8b 45 0c mov 0xc(%ebp),%eax
    80483cd: 89 45 fc mov %eax,-0x4(%ebp)
    80483d0: 8b 45 fc mov -0x4(%ebp),%eax
    80483d3: 89 44 24 08 mov %eax,0x8(%esp)
    80483d7: 8b 45 f8 mov -0x8(%ebp),%eax
    80483da: 89 44 24 04 mov %eax,0x4(%esp)
    80483de: c7 04 24 00 85 04 08 movl $0x8048500,(%esp)
    80483e5: e8 ee fe ff ff call 80482d8 <printf@plt>
    80483ea: c9 leave
    80483eb: c3 ret

    080483ec <main>:
    80483ec: 8d 4c 24 04 lea 0x4(%esp),%ecx
    80483f0: 83 e4 f0 and $0xfffffff0,%esp
    80483f3: ff 71 fc pushl -0x4(%ecx)
    80483f6: 55 push %ebp
    80483f7: 89 e5 mov %esp,%ebp
    80483f9: 51 push %ecx
    80483fa: 83 ec 14 sub $0x14,%esp
    80483fd: c7 44 24 04 14 00 00 movl $0x14,0x4(%esp)
    8048404: 00
    8048405: c7 04 24 0a 00 00 00 movl $0xa,(%esp)
    804840c: e8 63 ff ff ff call 8048374 <set_value_1>
    8048411: c7 44 24 04 14 00 00 movl $0x14,0x4(%esp)
    8048418: 00
    8048419: c7 04 24 0a 00 00 00 movl $0xa,(%esp)
    8048420: e8 4f ff ff ff call 8048374 <set_value_1>
    8048425: b8 00 00 00 00 mov $0x0,%eax
    804842a: 83 c4 14 add $0x14,%esp
    804842d: 59 pop %ecx
    804842e: 5d pop %ebp
    804842f: 8d 61 fc lea -0x4(%ecx),%esp
    8048432: c3 ret
    8048433: 90 nop
    8048434: 90 nop
    8048435: 90 nop
    8048436: 90 nop
    8048437: 90 nop
    8048438: 90 nop
    8048439: 90 nop
    804843a: 90 nop
    804843b: 90 nop
    804843c: 90 nop
    804843d: 90 nop
    804843e: 90 nop
    804843f: 90 nop

    08048440 <__libc_csu_fini>:
    8048440: 55 push %ebp
    8048441: 89 e5 mov %esp,%ebp
    8048443: 5d pop %ebp
    8048444: c3 ret
    8048445: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
    8048449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi

    08048450 <__libc_csu_init>:
    8048450: 55 push %ebp
    8048451: 89 e5 mov %esp,%ebp
    8048453: 57 push %edi
    8048454: 56 push %esi
    8048455: 53 push %ebx
    8048456: e8 4f 00 00 00 call 80484aa <__i686.get_pc_thunk.bx>
    804845b: 81 c3 01 12 00 00 add $0x1201,%ebx
    8048461: 83 ec 1c sub $0x1c,%esp
    8048464: e8 0f fe ff ff call 8048278 <_init>
    8048469: 8d bb 20 ff ff ff lea -0xe0(%ebx),%edi
    804846f: 8d 83 20 ff ff ff lea -0xe0(%ebx),%eax
    8048475: 29 c7 sub %eax,%edi
    8048477: c1 ff 02 sar $0x2,%edi
    804847a: 85 ff test %edi,%edi
    804847c: 74 24 je 80484a2 <__libc_csu_init+0x52>
    804847e: 31 f6 xor %esi,%esi
    8048480: 8b 45 10 mov 0x10(%ebp),%eax
    8048483: 89 44 24 08 mov %eax,0x8(%esp)
    8048487: 8b 45 0c mov 0xc(%ebp),%eax
    804848a: 89 44 24 04 mov %eax,0x4(%esp)
    804848e: 8b 45 08 mov 0x8(%ebp),%eax
    8048491: 89 04 24 mov %eax,(%esp)
    8048494: ff 94 b3 20 ff ff ff call *-0xe0(%ebx,%esi,4)
    804849b: 83 c6 01 add $0x1,%esi
    804849e: 39 fe cmp %edi,%esi
    80484a0: 72 de jb 8048480 <__libc_csu_init+0x30>
    80484a2: 83 c4 1c add $0x1c,%esp
    80484a5: 5b pop %ebx
    80484a6: 5e pop %esi
    80484a7: 5f pop %edi
    80484a8: 5d pop %ebp
    80484a9: c3 ret

    080484aa <__i686.get_pc_thunk.bx>:
    80484aa: 8b 1c 24 mov (%esp),%ebx
    80484ad: c3 ret
    80484ae: 90 nop
    80484af: 90 nop

    080484b0 <__do_global_ctors_aux>:
    80484b0: 55 push %ebp
    80484b1: 89 e5 mov %esp,%ebp
    80484b3: 53 push %ebx
    80484b4: 83 ec 04 sub $0x4,%esp
    80484b7: a1 7c 95 04 08 mov 0x804957c,%eax
    80484bc: 83 f8 ff cmp $0xffffffff,%eax
    80484bf: 74 12 je 80484d3 <__do_global_ctors_aux+0x23>
    80484c1: 31 db xor %ebx,%ebx
    80484c3: ff d0 call *%eax
    80484c5: 8b 83 78 95 04 08 mov 0x8049578(%ebx),%eax
    80484cb: 83 eb 04 sub $0x4,%ebx
    80484ce: 83 f8 ff cmp $0xffffffff,%eax
    80484d1: 75 f0 jne 80484c3 <__do_global_ctors_aux+0x13>
    80484d3: 83 c4 04 add $0x4,%esp
    80484d6: 5b pop %ebx
    80484d7: 5d pop %ebp
    80484d8: c3 ret
    80484d9: 90 nop
    80484da: 90 nop
    80484db: 90 nop

    Disassembly of section .fini:

    080484dc <_fini>:
    80484dc: 55 push %ebp
    80484dd: 89 e5 mov %esp,%ebp
    80484df: 53 push %ebx
    80484e0: 83 ec 04 sub $0x4,%esp
    80484e3: e8 00 00 00 00 call 80484e8 <_fini+0xc>
    80484e8: 5b pop %ebx
    80484e9: 81 c3 74 11 00 00 add $0x1174,%ebx
    80484ef: e8 2c fe ff ff call 8048320 <__do_global_dtors_aux>
    80484f4: 59 pop %ecx
    80484f5: 5b pop %ebx
    80484f6: c9 leave
    80484f7: c3 ret

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The first example is four statements; the second example is one statement. In this case it doesn't make much difference to the actual execution of the program. (Commas are necessary when you can only have one statement, such as in the opening parentheses of a for-loop.)

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by tabstop View Post
    The first example is four statements; the second example is one statement. In this case it doesn't make much difference to the actual execution of the program. (Commas are necessary when you can only have one statement, such as in the opening parentheses of a for-loop.)
    Hey TabStop assembly dump with objdum on linux 2.6.29
    doesn't show any difference with 4 arguments also strange

    08048374 <set_value_1>:
    8048374: 55 push %ebp
    8048375: 89 e5 mov %esp,%ebp
    8048377: 83 ec 28 sub $0x28,%esp
    804837a: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
    8048381: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
    8048388: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
    804838f: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
    8048396: 8b 45 08 mov 0x8(%ebp),%eax
    8048399: 89 45 f0 mov %eax,-0x10(%ebp)
    804839c: 8b 45 0c mov 0xc(%ebp),%eax
    804839f: 89 45 f4 mov %eax,-0xc(%ebp)
    80483a2: 8b 45 10 mov 0x10(%ebp),%eax
    80483a5: 89 45 f8 mov %eax,-0x8(%ebp)
    80483a8: 8b 45 14 mov 0x14(%ebp),%eax
    80483ab: 89 45 fc mov %eax,-0x4(%ebp)
    80483ae: 8b 45 fc mov -0x4(%ebp),%eax
    80483b1: 89 44 24 10 mov %eax,0x10(%esp)
    80483b5: 8b 45 f8 mov -0x8(%ebp),%eax
    80483b8: 89 44 24 0c mov %eax,0xc(%esp)
    80483bc: 8b 45 f4 mov -0xc(%ebp),%eax
    80483bf: 89 44 24 08 mov %eax,0x8(%esp)
    80483c3: 8b 45 f0 mov -0x10(%ebp),%eax
    80483c6: 89 44 24 04 mov %eax,0x4(%esp)
    80483ca: c7 04 24 70 85 04 08 movl $0x8048570,(%esp)
    80483d1: e8 02 ff ff ff call 80482d8 <printf@plt>
    80483d6: c9 leave
    80483d7: c3 ret

    080483d8 <set_value_2>:
    80483d8: 55 push %ebp
    80483d9: 89 e5 mov %esp,%ebp
    80483db: 83 ec 28 sub $0x28,%esp
    80483de: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
    80483e5: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
    80483ec: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp)
    80483f3: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
    80483fa: 8b 45 08 mov 0x8(%ebp),%eax
    80483fd: 89 45 f0 mov %eax,-0x10(%ebp)
    8048400: 8b 45 0c mov 0xc(%ebp),%eax
    8048403: 89 45 f4 mov %eax,-0xc(%ebp)
    8048406: 8b 45 10 mov 0x10(%ebp),%eax
    8048409: 89 45 f8 mov %eax,-0x8(%ebp)
    804840c: 8b 45 14 mov 0x14(%ebp),%eax
    804840f: 89 45 fc mov %eax,-0x4(%ebp)
    8048412: 8b 45 fc mov -0x4(%ebp),%eax
    8048415: 89 44 24 10 mov %eax,0x10(%esp)
    8048419: 8b 45 f8 mov -0x8(%ebp),%eax
    804841c: 89 44 24 0c mov %eax,0xc(%esp)
    8048420: 8b 45 f4 mov -0xc(%ebp),%eax
    8048423: 89 44 24 08 mov %eax,0x8(%esp)
    8048427: 8b 45 f0 mov -0x10(%ebp),%eax
    804842a: 89 44 24 04 mov %eax,0x4(%esp)
    804842e: c7 04 24 70 85 04 08 movl $0x8048570,(%esp)
    8048435: e8 9e fe ff ff call 80482d8 <printf@plt>
    804843a: c9 leave
    804843b: c3 ret


    Cheers

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Code:
    #include <stdio.h>
    
    int set_value_1(const int a, const int b,
                    const int c, const int d) {
      int x = 0;
      int y = 0;
      int z = 0;
      int w = 0;
      x = a, y = b, z = c, w = d;
      printf("%d %d %d %d\n", x, y, z, w);
    }
    
    int set_value_2(const int a, const int b,
                    const int c, const int d) {
      int x = 0;
      int y = 0;
      int z = 0;
      int w = 0;
      x = a;
      y = b;
      z = c;
      w  = d;
      printf("%d %d %d %d\n", x, y, z, w);
    }
    
    int main() {
      set_value_1(10, 20, 30, 40);
      set_value_1(10, 20, 30, 40);
    
      return 0;
    }

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by RockyMarrone View Post
    Hey TabStop assembly dump with objdum on linux 2.6.29
    doesn't show any difference with 4 arguments also strange





    Cheers
    I wasn't referring to assembly, but to C syntax. One example had 4 C statements in it, the other had one C statement.

  7. #7
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    one big difference is that , is an overloadable operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding the difference in two times
    By muthus in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2008, 06:36 PM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. Replies: 10
    Last Post: 11-06-2005, 09:29 PM
  5. Difference between macro and pass by reference?
    By converge in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2002, 05:20 AM