C/C++ Comparison

From Wiring

Jump to: navigation, search

The Wiring environment is written in C and C++. Programs written in Wiring are also translated to C++ and then run as C++ programs in the Wiring hardware.

Large distinctions between Wiring and C/C++ are the Wiring API and libraries and a simplified programming style that doesn't require users to understand more advanced concepts like classes, objects, pointers (while still making them accessible for advanced users). Such technical details must be specifically programmed in C/C++, but are integrated into Wiring, making programs shorter and easier to read.

Contents

Data

Wiring C
int x = 70; // Initialize

x = 30; // Change value

int x = 70; // Initialize

x = 30; // Change value

float x = 70.0;

x = 30.0;

float x = 70.0;

x = 30.0;

int[] a = {5, 10, 11}; // Create an array

a[0] = 12; // Reassign

int[] a = {5, 10, 11}; // Create an array
a[0] = 12; // Reassign

int a[8]; // Declare

a[0] = 1; // Initialize

int[] a[8]; // Declare

a[0] = 1; // Initialize

int *a = new int[8]; // Declare

a[0] = 1; // Initialize

int[] a = new int[8]; // Declare
a[0] = 1; // Initialize

Control

Wiring C

void setup() {

  // Statements

}

void loop() {

  // Statements

}

void main() {

  // Statements

}

 

for(int a=45; a<=55; a++) {
// Statements

}

for(int a=45; a<=55; a++) {
// Statements

}

if(c==1) {
// Statements

}

if(c==1) {
// Statements

}

if(c!=1) {
// Statements

}

if(c!=1) {
// Statements

}

if(c < 1) {
// Statements

}

if(c < 1) {
// Statements

}

if(c >= 1) {
// Statements

}

if(c >= 1) {
// Statements

}

if((c >= 1) && (c < 20)) {
// Statements

}

if((c >= 1) && (c < 20)) {
// Statements

}

if(c >= 20) {
// Statements 1

} else if (c == 0) {
// Statements 2
} else {
// Statements 3

}

if(c >= 20) {
// Statements 1

} else if (c == 0) {
// Statements 2
} else {
// Statements 3
}

Structure

Wiring C

// Comment

// Comment
void doIt(int x) {

  // Statements
}

doIt(x);

void doIt(int x) {

  // Statements
}

doIt(x);

int square(int x)

{
  return x*x;
}

square(X);

int square(int x)

{
  return x*x;
}

square(X);

Printing

Wiring C

Serial.println("hello world");

printf("hello world\n");
int a = 55;

Serial.print(a, DEC);

int a = 55;

printf("%d", a);

int a = 55;

Serial.print("a is ");
Serial.print(a, DEC);

int a = 55;

printf("a is %d", a);

Personal tools