Difference between revisions of "Category:C"

From ElectroDragon
Jump to navigation Jump to search
(Operations)
(Operations)
 
(No difference)

Latest revision as of 13:19, 8 November 2019

Language

Compiler

  • Linux GCC
  • HI-TECH PICC for PIC

Declaration

Data type

Classic basic primitive types may include:

  • Character (character, char);
  • Integer (integer, int, short, long, byte) with a variety of precisions;
  • Floating-point number (float, double, real, double precision);
  • Fixed-point number (fixed) with a variety of precisions and a programmer-selected scale.
  • Boolean, logical values true and false.
  • Reference (also called a pointer or handle), a small value referring to another object's address in memory, possibly a much larger one.

More sophisticated types which can be built-in include:

  • Tuple in Standard ML, Python, Scala
  • List in Common Lisp, Scheme, Haskell
  • Complex number in C99, Fortran, Common Lisp, Python, D, Go
  • Rational number in Common Lisp, Haskell
  • Associative array in Perl, Python, Ruby, Javascript, Lua, D, Go
  • First-class function, in all functional languages, Javascript, Lua, D, Go, and in newer standards of C++, Java, C#, Perl
type width default signed range unsigned range
bool 1 bit unsigned - 0, 1
char 8 bits, 1 byte signed -128 to +127 0 to +255
short 16 bits, 2 bytes signed -32,768 to +32,767 0 to +65,535
int 16 bits, 2 bytes signed -32,768 to +32,767 0 to +65,535
long 32 bits, 4 bytes signed -2,147,483,648 to +2,147,483,647 0 to +4,294,967,295
float 4 bytes IEEE 754 signed 1.175494351E-38 to 3.402823466E+38
pointer 1, 2, 3 or 4 bytes generic


Easy to remember integer data types :

data type width signed/
unsigned
range
s8 8 bits (1 byte) signed -128 to +127
s16 16 bits (2 bytes) signed -32,768 to +32,767
s32 32 bits (4 bytes) signed -2,147,483,648 to +2,147,483,647
s64* 64 bits (8 bytes) signed −9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
u8 8 bits (1 byte) unsigned 0 to +255
u16 16 bits (2 bytes) unsigned 0 to +65,535
u32 32 bits (4 bytes) unsigned 0 to +4,294,967,295
u64* 64 bits (8 bytes) unsigned 0 to +18,446,744,073,709,551,615

Data Format

From to function example description reference
String char toCharArray sensorVal.toCharArray(sensorPrintout, 4); TFT
float string dtostrf dtostrf(f_volt, 6, 2, volt_char); f_volt is float value
Example Example Example
  • printf
  • String aaa = String(bbb) // bbb is char array

Data Type

- - -
Byte 8 bit Example
Int Example Example
Char Example Example
Hex Example Example

Header file Definition

Define macro

For examples set pins for segment display, file seg.h

  • Further refer to SFR_Macro.h in BSP of nuvoton
#define set_a      P05 = 1
#define set_b      P03 = 1
#define set_c      P10 = 1
#define set_d      P01 = 1
#define set_e      P07 = 1
#define set_f      P02 = 1
#define set_g      P14 = 1
#define set_dot    P00 = 1

Define type

typedef bit                   BIT;
typedef unsigned char         UINT8;
typedef unsigned int          UINT16;
typedef unsigned long         UINT32;

typedef unsigned char         uint8_t;
typedef unsigned int          uint16_t;
typedef unsigned long         uint32_t;

Complier

Common Header

Subcategories

This category has only the following subcategory.

Pages in category "C"

The following 2 pages are in this category, out of 2 total.