Changes between Version 42 and Version 43 of ResumedC


Ignore:
Timestamp:
Sep 9, 2009, 5:23:55 PM (15 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ResumedC

    v42 v43  
    1717{{{
    1818#!C
    19 /* Wrong way: */
     19   /* Wrong way: */
    2020if (strcmp(string1, string2))
    21  ...
    22 
    23 /* Easy-to-understand way: */
     21   /* Easy-to-understand way: */
    2422if ((strcmp(string1, string2) == 0)
    25  ...
    26 }}}
     23
     24   /* Wrong way: */
     25long *pTab[10];       // It creates an array with 10 pointers to the type long
     26   /* Easy-to-understand way: */
     27long (*pTab)[10];     // It creates a pointer to an array with 10 elements in type long
     28}}}
     29
     30Note that using this way, not only your code is better to read but also a lot less error-prone specially for you, and for who needs to modify it, so that the program will do something different at what you are waiting to do, or that who reads it will think that it does something when is doing another thing.
     31
     32'''Tip''': Apart of that is more easy to read and less error-prone the method of using parentheses, in order to made your code clear and/or if you don't know the order of on which order the things are called in a line, use parentheses.
    2733
    2834By separating the source code in multiple files, you have your code a lot more organized and there's a lot more easy to read and specially to search something between the code.
     
    221227struct time lap[MAX_LAPS];
    222228  /* This call creates an array called 'lap' of MAX_LAPS elements that are structures of type 'time' */
     229struct time t1, t2, *pLap, lap[100];
     230  /* Different methods to create structures */
    223231
    224232/* You can also set values like */
     
    286294pa = a;    // pa points to a[0]
    287295
    288 /* array of 5 elements */
     296   /* array of 5 elements */
    289297char arr[5];
    290298
    291 /* pointer 'arr_p' to the array 'arr' */
     299   /* pointer 'arr_p' to the array 'arr' */
    292300char *arr_p = &arr[0];
    293 
    294 *(array_p + 1) /* Equivalent */
    295 (*array_p + 1 ) /* Not Equivalent */
     301*(array_p + 1)    // Equivalent
     302(*array_p + 1 )   // Not Equivalent
     303
     304   /* All these methods are equivalent: */
     305&a[i] ,   a+i  ,   pa+i  , &(pa[i])    // Pointers to the 'i' element of an array
     306 a[i] , *(a+i) , *(pa+i) ,   pa[i]     // In the same method way, the 'i' element of an array (no-pointer)
    296307}}}
    297308