Changes between Version 16 and Version 17 of ResumedC


Ignore:
Timestamp:
May 13, 2009, 6:55:04 PM (15 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ResumedC

    v16 v17  
    101101Everytime you enclose a variable declaration inside a block '''{}''', it is limited to this section (not works out of it), if you have variables declared out of any function and/or out of main(), it is supported by all the entire application. Also, if you declare a variable inside a block that is already declared outside of it, then for inside the block it is used only the new declared one, not the one declared out of it, however, this practice is not good since may be very confusing.
    102102
    103 '''Static''': By declaring a '''static''' variable (or function) out of any function (global mode), it will be used only in the actual file (not a real file, but more like a ''compilation unit''), this is good for a better optimization but if you want to use it in other ''files'', you need to declare it by '''extern'''. By other side, if you declare it in a block or a loop something like  ''static int foo = 5;''  you can do operations to this variable without worry about the declaration of the value 5, because when is in mode static, it is only declared to the selected value the first time, the next times that are called is ignored.
    104 
    105103'''signed''': means ''with sign'', so, values negative and positive, for example if the '''char''' variable has a limit of 255 values, using the '''sign''' mode we can use from '''-128''' (negative) to '''127''' (positive), and using '''unsigned''' we can use from '''0''' to '''255'''
     104
     105==== Extern ====
     106You should '''ignore''' it since its the default when there's no anything set. It means that you can use and/or re-declare a function on other ''files'' of the code
     107
     108==== Static ====
     109You can use ''static'' inside a function or outside it, it has two differents meanings:
     110     * Inside a function: You can ''pre'' set a value to a variable ''(static int foo = 5)'', then the first time you enter on the function it will be set to 5, but the next times it not set again, it just remember the last value used
     111     * Outside a function (global mode): You will use it only in the actual file (compilation unit), good for optimization but you can't use it on other files
    106112
    107113
     
    151157
    152158=== Functions ===
    153 
    154 A basic function:
     159A function can be (re)called too (inside himself), this is known as ''recursion''
     160
     161==== Basic example ====
    155162
    156163{{{
     
    161168 This function means: it needs to return a ''float'' variable, it is called with two parameters of type float too, this function can't modify directly the variables (width or height), for that is needed to use pointers (because we have the address (of memory) to that data instead the data value, so we can modify its content (data))
    162169
     170
     171==== Structure of a function ====
     172{{{
     173#!C
     174[class_of_memorization] [type] name( [arguments] )
     175// class: It will be static or extern (see Variables section)
     176// type: It will be anything (void, int, char, a pointer...), except an array
     177// arguments: Arguments to pass to a function, if any
     178}}}
     179
     180
     181==== Modification of variables by pointers ====
    163182This is a example of a function call and modification by using pointers:
    164183{{{
     
    173192}}}
    174193
    175 A function can be (re)called too, this is known as ''recursion''
     194
     195==== Prototype of Functions ====
     196When there's no arguments for the function, just use the void value
     197
     198When there's arguments, you should add too a name of variable after it, the mean of this is just to be more easy to understand when reading the headers file for example
     199{{{
     200#!C
     201double calc( double base, double exponent);
     202}}}
     203
    176204
    177205
     
    249277}}}
    250278
    251 '''Double pointers''': The double pointer can be used for 2 differents things:
     279==== Double pointers ====
     280The double pointer can be used for 2 differents things:
    252281 * A pointer that points to a pointer, so that you can change the value of the original pointer (address value)
    253282   * ''To modify the value of a variable using pointers in a function, you need to pass the address of that variable'': Same thing when you try to modify the address of a pointer (pointer of a pointer)