C Operators

% Remainder after division (modulo division) The result of a modulo division is the remainder of an integer division of the given numbers. Examples

Read More

if

If (variable) if (some_variable) do_something; Anything that's not a 0 is a true value in if If with load of a return value into a variable if ((count = some_function()) > -1) { //count contains the return value }  

Read More

Constants

‘u’ or ‘U’ to indicate an unsigned constant, like 33u ‘ul’ or ‘UL’ to indicate an unsigned long constant, like 32767ul

Read More

State ? ( ) : ( )

Usage Examples #define USART_DIR_TX(state) (state ? ([true]) : ([false])) (state ? true : false) //1:0 #define OUTPUT_PIN(state) (state ? LATAbis.LATA1 = 1 : LATAbis.LATA1 = 0) //1:0 bytesThisSector = (bytesLeftToWrite > 512) ? 512 : bytesLeftToWrite; #define LED_OUTPUT_ON(state) (state ? (rs485_leds_output |= 0x01) : (rs485_leds_output &= ~0x01))

Read More

Defines

General Define Usage Create a define: #define NUM_OF_ANODES 2 In code: #if NUM_OF_ANODES == 2 #endif #ifdef #ifndef #elif #else #endif #if defined(PIC18F87J50_PIM) || defined(PIC18F46J50_PIM) || defined(PIC18F_STARTER_KIT_1) Multi Line Continuation Character Use the ‘\’ backslash character at the end of each line except for the last. If you have any comments surround them with /* […]

Read More

Line Continuation Character

\ //Put a ‘\’ at the end of a line to signify to compiler next line shoud be part of this line //This is useful for defines etc, e.g.:- #define USBInitialize(x) \ { \ USBHostInit(x); \ }

Read More