Changes between Version 4 and Version 5 of ResumedC


Ignore:
Timestamp:
Apr 28, 2009, 4:56:20 PM (16 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ResumedC

    v4 v5  
    157157
    158158
     159=== Structures ===
     160
     161A structure can contains any variable types sections, and also arrays and sub-structures
     162
     163{{{
     164#!C
     165/* Note: 'time' is a previously-defined structure' */
     166struct time lap[MAX_LAPS];
     167  /* This call creates an array called 'lap' of MAX_LAPS elements that are structures of type 'time' */
     168
     169/* You can also set values like */
     170lap[count].hour = hour;
     171  /* This set the value 'hour' on the 'hour' (structure element) of the 'count' (array element) of lap */
     172
     173/* Initialization of an array of structures: */
     174struct time start_stop[2] = {
     175  { 10, 0 },
     176  { 12, 0 }
     177};
     178}}}
     179
     180
     181==== Packaged structures ====
     182Image an application that stupidly takes a lot of storage but very few 'cpu' usage and you will need to optimize it for data, you can set the value of the bits to use for the structure elements, like:
     183{{{
     184#!C
     185struct item {
     186   unsigned int seen:1;
     187   ...
     188   }
     189/* Now the variable 'seen' (seen or not seen) only takes one BIT */
     190}}}
     191 The bad point of this usage is that it the access to this data is pretty more slow than in normal mode, so do this only when is really needed to save storage space.
     192
     193
     194
     195
     196
     197
     198=== Pointers ===
     199
     200With pointers you can modify directly the data of a variable (see #functions)
     201
     202
     203
     204
     205
     206
     207
     208=== Typedef ===
     209
     210With typedef we can define our own variable types, for example:
     211{{{
     212#!C
     213typedef static long int mylongintstatic;
     214
     215/* example of declare a variable of this new type: */
     216mylongintstatic var1 = 5;
     217}}}
     218
     219Note that ''typedef'' could be considered similar to the #define statement, but can define more complex objects like:
     220{{{
     221#!C
     222/* group is a type of 10-elements array */
     223typedef int group[10]
     224}}}
     225
     226
     227
     228
     229
     230
     231=== Conversion ===
     232
     233You can convert a variable type to other at any time by:
     234{{{
     235#!C
     236int value = 5;
     237printf ("%f", (float)value );
     238}}}
     239
     240
     241
     242
     243
     244
     245
     246=== Misc ===
     247
     248The '''header''' files should be limited to have only types and definitions
     249
     250
     251
     252
     253
     254
     255
    159256
    160257
     
    163260If you want to see the preprocessor messages (values), you can see them when compiling by using the -E option (in gcc)
    164261
    165 If you want to pass something defined (to use with #ifdef, for example)
     262If you want to pass something defined (to use with #ifdef, for example) in the moment of the compilation, you will add options to the compiler (gcc) like -DDEBUG or -DMAX=10
    166263
    167264