Pages: 1 ... 4 5 [6]   Go Down
Author Topic: Programming in C  (Read 3324 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not quite nerdy enough. It was developed to aid porting Unix.

Nope. Writing it. If you think the first version of UNIX was written in assembly language, that is a mistake.

Never really searched that deep into the origins of Unix, but unless this Wikipedia article is wrong, C was developed to overcome the shortcomings of B in porting the assembly-coded PDP-7 version of Unix to a PDP-11.

Here's the relevant paragraph:
Quote
The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a PDP-11. B's inability to take advantage of some of the PDP-11's features, notably byte addressability, led to the development of an early version of C.

The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition of struct types, the C language had become powerful enough that most of the Unix kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the Multics system (written in PL/I), and MCP (Master Control Program) for the Burroughs B5000 written in ALGOL in 1961.)

And here's the page address:

http://en.wikipedia.org/wiki/C_%28programming_language%29

Very interesting (and nerdy) stuff smiley
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16516
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not quite nerdy enough. It was developed to aid porting Unix.

Nope. Writing it. If you think the first version of UNIX was written in assembly language, that is a mistake.

Well extracted from wikipedia:

Quote
Early developments


Ken Thompson and Dennis Ritchie, developers of the C programming language.
The initial development of C occurred at AT&T Bell Labs between 1969 and 1973;[3] according to Ritchie, the most creative period occurred in 1972. It was named "C" because its features were derived from an earlier language called "B", which according to Ken Thompson was a stripped-down version of the BCPL programming language.
The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a PDP-11. B's inability to take advantage of some of the PDP-11's features, notably byte addressability, led to the development of an early version of C.
The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition of struct types, the C language had become powerful enough that most of the Unix kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the Multics system (written in PL/I), and MCP (Master Control Program) for the Burroughs B5000 written in ALGOL in 1961.)

So it says there that unix did get started as an assembly created OS?

Lefty
Logged

Offline Offline
God Member
*****
Karma: 21
Posts: 650
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
b) use different #include directives for the different environment
I'm not too sure what you mean here by different directives? Do you mean for example, say I wrote my own servo library - that I'd write #include <myownservolib.h>. Or are you referring to including again, for example, standard libraries that come with Atmel Studio?

The latter.

Quote
c) write your own function prototypes (just function declarations that you put near the start of your program to simplify things for the compiler when it comes across a call to a function that it hasn't yet seen in the source file.)

Again, a little lost here. A function for example would be digitalWrite?

Read your K&R or other C primer on "function prototypes". You won't have seen these in Arduino, because they are generated automatically in the sketch -> "real" C++ source file conversion stage by the Arduino IDE.

Regarding point e) - I agree this seems the most important, writing or finding libraries that provide the functions such as milli() micro() etc as my codes have used these quite extensively. I need to find out how to write a library. Just on a side note, is wire.h included automatically? As I haven't included it in my codes using functions such as millis, and all works fine.

Yes, the wiring stuff gets included automatically in an Arduino sketch, from the  #include <Arduino.h> directive.
Logged

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

Offline Offline
God Member
*****
Karma: 21
Posts: 650
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

C was developed to overcome the shortcomings of B in porting the assembly-coded PDP-7 version of Unix to a PDP-11.

Here's the relevant paragraph:
Quote
The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a PDP-11. B's inability to take advantage of some of the PDP-11's features, notably byte addressability, led to the development of an early version of C.

The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition of struct types, the C language had become powerful enough that most of the Unix kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the Multics system (written in PL/I), and MCP (Master Control Program) for the Burroughs B5000 written in ALGOL in 1961.)

And here's the page address:

http://en.wikipedia.org/wiki/C_%28programming_language%29

Very interesting (and nerdy) stuff smiley

OK, I take it back -- there was a version of UNIX in assembly language. How about that. Apologies to AWOL!

But the point remains that C was developed firstly as a _systems_ programming language, with the practical purpose of implementing the UNIX kernel. I think one of the reasons it has lasted so well is because it grew out of the immediate need for a tool for this very practical and challenging task. Only what was needed to do the job was included. All very lean and minimalist -- no extra baggage here.

Logged

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which of the files in the Arduino package can I find out which and what .h libraries are included?

Just trying to figure out exactly what needs to be included...
« Last Edit: November 24, 2012, 02:04:35 pm by jtw11 » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing needs to be included, per se.

However if you look at some of the low-level .h files which come with the IDE you will see helpful defines for things like the registers used by the processor.

As an example, one of Timer 2's registers:

Code:
#define OCR2A _SFR_MEM8(0xB3)

And 0xB3 is indeed where that register is on the Atmega328P.

You could read any book on C (or C++), just disregarding the parts where their examples interact with higher-level operating systems (like reading or writing files). And in the case of C++, disregard the part about exception handling, since that is turned off by compiler flags when the IDE compiles your sketch.

You can compile a minimal sketch:

Code:
int main ()
  {
  return 0;
  }

Quite short:

Code:
Binary sketch size: 176 bytes (of a 32,256 byte maximum)

Most of that is interrupt vectors and a bit of compiler prologue, which you can omit (as bootloaders do).

If you start fleshing out that minimal sketch you would find that it would be your job to make things like millis() work, because the timers hadn't been initialized.
Logged

Offline Offline
God Member
*****
Karma: 21
Posts: 650
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just on a side note, is wire.h included automatically? As I haven't included it in my codes using functions such as millis, and all works fine.

Just noticed this -- don't confuse "Wire.h" with "wiring.h".

Wire.h is a user library, implementing an I2C interface, found in the in the libraries/Wire subdirectory.

For wiring.h, you would look in the hardware/arduino/cores/arduino subdirectory.
Logged

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah - thank you. I have only ever used wire.h once, so missed this! Thanks.
Logged

Pages: 1 ... 4 5 [6]   Go Up
Jump to: