Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C Is Not a Low-level Language. Your computer is not a fast PDP-11

Name: Anonymous 2018-10-18 20:01

For a language to be "close to the metal," it must provide an abstract machine that maps easily to the abstractions exposed by the target platform. It's easy to argue that C was a low-level language for the PDP-11.

it is possible to make C code run quickly but only by spending thousands of person-years building a sufficiently smart compiler—and even then, only if you violate some of the language rules. Compiler writers let C programmers pretend that they are writing code that is "close to the metal" but must then generate machine code that has very different behavior if they want C programmers to keep believing that they are using a fast language.

https://queue.acm.org/detail.cfm?id=3212479

Name: Anonymous 2018-10-19 13:19

int redPin=11;
int greenPin=10;
int bluePin=9;
int buzzerPin=7;

int potPin=1;
int sensorPin=7;

long red=0xFF0000;
long green=0x00FF00;
long blue =0x000080;
int band =50;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin,OUTPUT);
pinMode(buzzerPin,OUTPUT);
}
void loop()
{
int gsr = analogRead(sensorPin);
int pot = analogRead(potPin);
if (gsr > pot + band)
{setColor(red);
beep();
}
else if (gsr <pot -band)
{
setColor(red);
beep();
}
else if (gsr <pot - band)
{
setColor(blue);
}
else
{
setColor(green);
}
}
void setColor(long rgb)
{
int red=rgb >> 16;
int green=(rgb>>8) & 0xFF;
int blue = rgb & 0xFF;
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
void beep()
{
for(int i = 0;i < 1000; i++)
{
digitalWrite(buzzerPin, HIGH);
delayMicroseconds(100);
digitalWrite(buzzerPin, LOW);
delayMicroseconds(100);
}
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List