Author Topic: Want to learn "C"  (Read 14346 times)

0 Members and 1 Guest are viewing this topic.

Offline alan monro

  • Contributor
  • Posts: 17
  • Country: au
Want to learn "C"
« on: September 30, 2012, 12:12:14 am »
Would anybody please tell me if there is a better book than "C" for dummies as there are many projects I wish to make using the Arduino . I have already have a evaluation  board  and have programed a flashing led , but , that is only the smallest fraction of what that  powerful  computer can do. Thank you, ..............................Alan
« Last Edit: September 30, 2012, 12:14:50 am by alan monro »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18911
  • Country: nl
    • NCT Developments
Re: Want to learn "C"
« Reply #1 on: September 30, 2012, 12:42:45 am »
Well there is "the C language by Kernigham & Ritchie": http://zanasi.chem.unisa.it/download/C.pdf. This is written by the inventors of the C language. Some regard this book as the ultimate C bible because there is no book closer to the source of the C language  8)

Besides that a good way to learn is to look at software other people wrote. Some examples are bad and some are good so when looking for a solution make sure to look at at least 5 different solutions and pick one that looks uncomplicated and you can understand.
« Last Edit: September 30, 2012, 12:44:51 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline oldrose

  • Contributor
  • Posts: 13
Re: Want to learn "C"
« Reply #2 on: September 30, 2012, 12:46:37 am »
Every C programmer should have "The C Programming Language" by Kernighan and Ritchie and I highly recommend "A Book on C" by Kelley and Pohl.

 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 9630
  • Country: us
Re: Want to learn "C"
« Reply #3 on: September 30, 2012, 12:47:47 am »
Tread carefully though: Arduino sketches are not written in C, even though the language is similar.
I'm not an EE--what am I doing here?
 

Offline updatelee

  • Contributor
  • Posts: 43
Re: Want to learn "C"
« Reply #4 on: September 30, 2012, 01:45:42 am »
I learned in University on the Deitel and Deitel books, they are excellent.

UDL
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Re: Want to learn "C"
« Reply #5 on: September 30, 2012, 03:42:28 am »
K&R is the reference, and important as it is to read and own, if it were perfect there wouldn't be so many other books trying to supplement it. The book Deep_C_Secrets helped me understand C better than any other. It's context is way out of date, but the concepts that it explains are timeless. I'm sure it's out of print, but maybe a search in Amazon or Abebooks will turn up a copy.
 

Offline poptones

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: 00
 

Offline Pagweb

  • Contributor
  • Posts: 6
  • Country: us
Re: Want to learn "C"
« Reply #7 on: September 30, 2012, 06:51:53 pm »
I learned C at my university too. The book we used was 'Problem Solving and Program Design in C' by Hanly Koffman. Is a good book for beginners and it has examples and practice problems. You can get a used version in Amazon for like $10.
 

Offline grumpydoc

  • Super Contributor
  • ***
  • Posts: 2701
  • Country: gb
Re: Want to learn "C"
« Reply #8 on: September 30, 2012, 07:00:04 pm »
K&R is probably my favourite book on any programming language. It sets out to describe the C language and does so with the minimum of fuss and extraneous detail.

It helps that K&R C is a very compact language - ANSI C has bloated somewhat and C++, much as I like it, is actually a nightmare.

It is an excellent example of the Unix philosophy of "one task, done well" and I thoroughly recommend it if you are learning C.

However you also need a good reference on the platform - modern systems are much more than the programming language and you need to know as much about he environment as possible to make effective use of it.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Want to learn "C"
« Reply #9 on: September 30, 2012, 07:03:23 pm »
http://kat.ph/expert-c-programming-deep-c-secrets-peter-van-der-linden-pdf-t6506890.html

Oh, come on. One doesn't become an expert out of nothing by reading an expert/secret book. Such books are snake oil.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline mtkaalund

  • Contributor
  • Posts: 32
  • Country: dk
Re: Want to learn "C"
« Reply #10 on: September 30, 2012, 07:57:29 pm »
Tread carefully though: Arduino sketches are not written in C, even though the language is similar.

And what do you based that on?
The arduino "language" is just a framework, that you program around, but it stil uses AVR-GCC and AVR-LIBC http://arduino.cc/en/Hacking/BuildProcess
"Keep buggering on" -- Winston Churchill
VIR => V = I*R, neat ;)
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14441
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Want to learn "C"
« Reply #11 on: September 30, 2012, 08:04:16 pm »
I got a book called "programming in c" by Stephen kochan it is very good. To be honest just reading others programs won't help one little bit unless you know so c, I'd prefer a less compact language, in the long run it would be faster for me to use and understand.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 9630
  • Country: us
Re: Want to learn "C"
« Reply #12 on: September 30, 2012, 08:33:31 pm »
And what do you based that on?
The arduino "language" is just a framework, that you program around, but it stil uses AVR-GCC and AVR-LIBC http://arduino.cc/en/Hacking/BuildProcess

I base it on the link you provided.

The C programming language consists of the standard language syntax and standard set of libraries (with a corresponding set of standard named header files).

The Arduino programming language uses different libraries and header files and macro definitions, and it also includes elements of C++ (which is not C).

So although programming an Arduino may be similar to writing C, it is not C. If you try to work through K&R and follow the examples and exercises as given you will run into trouble.

An experienced person may be fully aware of this, but it is not something that may be equally clear to beginners.
« Last Edit: September 30, 2012, 09:46:34 pm by IanB »
I'm not an EE--what am I doing here?
 

Online TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: Want to learn "C"
« Reply #13 on: September 30, 2012, 09:12:51 pm »
I have to agree with IanB here.  Strictly speaking sketches are neither C or C++.  This can really trip-up a newcomer.  For good or bad  Arduino sketches are their own little beast. 

For example, try putting a struct declaration in your Arduino sketch.  It won't work.  It does in C/C++.  Someone trying to learn C or C++ will find this very frustrating.

Someone who already knows C/C++ will find this merely quirky.  (A 10-second Google search reveals that the workaround is to simply put the declaration in a .h file.)  A noob will likely waste countless hours with a problem like this, however, and will likely come away feeling duped into thinking that Arduino sketches are "just" C/C++ code.
 

Offline phil_jp1

  • Regular Contributor
  • *
  • Posts: 103
  • Country: ua
Re: Want to learn "C"
« Reply #14 on: September 30, 2012, 09:42:23 pm »
It's has been mentioned earlier and I will repeat it:
Apart from reading a book(doesn't matter how good that book would be), you should learn from others code! Learn design patterns in process.

Another really good way to learn is to take someone's code, compile it to see if it works, then change something and compile it again, pay attention to compiler generated errors and warnings, fix the problems and run the program, then repeat this cycle again.
http://JumperOne.com - Electronic projects, tutorials, hacks, etc.
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Re: Want to learn "C"
« Reply #15 on: October 01, 2012, 01:04:49 am »
http://kat.ph/expert-c-programming-deep-c-secrets-peter-van-der-linden-pdf-t6506890.html

Oh, come on. One doesn't become an expert out of nothing by reading an expert/secret book. Such books are snake oil.

Since I recommended this book, I'll defend it. The author, Van Linden, managed the compiler team at SUN, and many of the "secrets" he reveals are things that anyone who has actually implemented a compiler would know. If you don't have this experience, the insights might be hard to come by otherwise. His introductory book on Java (also badly dated now) was similarly great.
 

Offline alan monro

  • Contributor
  • Posts: 17
  • Country: au
Re: Want to learn "C"
« Reply #16 on: October 01, 2012, 06:30:21 am »
Every C programmer should have "The C Programming Language" by Kernighan and Ritchie and I highly recommend "A Book on C" by Kelley and Pohl.

Thank you....................Alan
 

Offline alan monro

  • Contributor
  • Posts: 17
  • Country: au
Re: Want to learn "C"
« Reply #17 on: October 01, 2012, 06:32:53 am »
Well there is "the C language by Kernigham & Ritchie": http://zanasi.chem.unisa.it/download/C.pdf. This is written by the inventors of the C language. Some regard this book as the ultimate C bible because there is no book closer to the source of the C language  8)

Besides that a good way to learn is to look at software other people wrote. Some examples are bad and some are good so when looking for a solution make sure to look at at least 5 different solutions and pick one that looks uncomplicated and you can understand.

Thanks to everybody who gave suggestions..............................................Alan
 

Offline alan monro

  • Contributor
  • Posts: 17
  • Country: au
Re: Want to learn "C"
« Reply #18 on: October 01, 2012, 06:36:32 am »
Every C programmer should have "The C Programming Language" by Kernighan and Ritchie and I highly recommend "A Book on C" by Kelley and Pohl.
[/



Thank you I will download the book you so kindly gave me. ...............................................Alan
 

Offline T4P

  • Super Contributor
  • ***
  • Posts: 3706
  • Country: sg
    • T4P
Re: Want to learn "C"
« Reply #19 on: October 01, 2012, 07:12:56 am »
Oh, come on. One doesn't become an expert out of nothing by reading an expert/secret book. Such books are snake oil.
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #20 on: October 01, 2012, 06:22:30 pm »
My 2 cents worth: while not strictly an elementary instruction book, the "Elements of C Programming Style" by Ranade and Nash can be worth checking. Most of the guidance given in there is as valid today as the day it was written. Works for me at least.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline Ferroto

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: ca
Re: Want to learn "C"
« Reply #21 on: October 02, 2012, 12:10:32 pm »
Even better then a book.

 

Offline alan monro

  • Contributor
  • Posts: 17
  • Country: au
Re: Want to learn "C"
« Reply #22 on: October 02, 2012, 10:14:40 pm »
Thanks Ferroto.....................................Alan
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 892
  • Country: us
Re: Want to learn "C"
« Reply #23 on: October 04, 2012, 09:23:44 pm »
Even better then a book.

Ugh. That's the thing with IDEs--you spend an hour screwing around with project and Makefile creation before you can even get to running some C code. Yuck.

Back around the time when dirt was invented, I learned C on a PDP-11 running Unix. I had a copy of K&R on the desk beside me and worked through simple examples in minutes using just a command line:

$ ed hello.c
a
#include <stdio.h>
int main(int argc, char *argv) {
 printf("Hello World!\n");
}
.
w
q
$ cc hello.c
$ ./a.out
Hello World!
$

The same thing still works on my Mac today. Woo hoo!

You kids can keep your IDEs.  :P
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #24 on: October 05, 2012, 07:25:03 am »
An hour is a long time (for IDE setup)? Do you honestly know a single SW project that failed because the IDE took so long to set up?
There are pros and cons for IDE and non-IDE project setup. Some advanced things are a bit difficult to do in an IDE environment but your basic project dependencies, tool parameterization  and build is not one of them. That is one big reason why i find myself doing everything in an IDE these days (at least for AVR-GCC projects).
Some like to bash e.g. the AVR Studio in its different versions but i can live with it quite nicely. And as to project setup, it takes all of ca. 10 seconds and you are good to go. For me it is a big value that the IDE lets me concentrate on solving the software creation task, not mess with tool setup and operation at every iteration.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline glee

  • Contributor
  • Posts: 32
Re: Want to learn "C"
« Reply #25 on: October 05, 2012, 09:50:57 am »
I'd suggest that the book that's right for you depends on your previous programming experience. If you are an experienced coder in other languages, you may find yourself empathising with those that hold K&R in such high esteem. If this is your first exposure to a low-level language you may find that same book a little opaque, or at least not very "tutorial" in style. I think I would give a second endorsement for  "Programming in C" by Stephen Kochan for someone new to programming attempting to learn C.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 892
  • Country: us
Re: Want to learn "C"
« Reply #26 on: October 05, 2012, 02:18:28 pm »
Do you honestly know a single SW project that failed because the IDE took so long to set up?
No, of course not.

IDEs are fine, but I think of IDEs as a nice-to-have rather than a requirement, as long as they don't interfere with automated builds. For learning though, there's a lot to be said for going back to basics, especially with C. When you're learning, it's usually with small programs that demonstrate particular language features. IDEs, on the other hand, are designed to handle large sprawling programs that a beginner shouldn't have to deal with.
 

Offline aluck

  • Regular Contributor
  • *
  • Posts: 246
  • Country: ru
Re: Want to learn "C"
« Reply #27 on: October 05, 2012, 04:09:05 pm »
Since I recommended this book, I'll defend it. The author, Van Linden, managed the compiler team at SUN, and many of the "secrets" he reveals are things that anyone who has actually implemented a compiler would know.
Spectacular book! I wonder why it is not very popular and widely-known.
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #28 on: October 05, 2012, 08:37:11 pm »
[...]
IDEs are fine, but I think of IDEs as a nice-to-have rather than a requirement, as long as they don't interfere with automated builds.
Sure, an IDE is hardly mandatory - at least i am not aware of any environment save possibly the Arduino, where you _must_ have an IDE. But i don't quite get why an IDE would interfere with an automated build, rather it will facilitate such builds by creating the dependencies automatically.
Quote
For learning though, there's a lot to be said for going back to basics, especially with C. When you're learning, it's usually with small programs that demonstrate particular language features. IDEs, on the other hand, are designed to handle large sprawling programs that a beginner shouldn't have to deal with.
When one is a beginner and learning the basics of a programming language i would think an IDE is just the thing to have. That way the poor beginner is somewhat isolated from the possibly complex machinery of a build. When he/she later wishes to understand it - if ever - many IDEs provide a view to that as well. And if not, there is always the fully manual option...
Nothing sings like a kilovolt.
Dr W. Bishop
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18911
  • Country: nl
    • NCT Developments
Re: Want to learn "C"
« Reply #29 on: October 05, 2012, 09:13:37 pm »
And lets not forget a good IDE has a good editor which lets you rename variables and functions across several files, keep a history of changes, does code completion, shows which functions are in a file, where variables are declared, etc, etc. A good IDE should make dealing with the source code much easier.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 892
  • Country: us
Re: Want to learn "C"
« Reply #30 on: October 05, 2012, 11:17:57 pm »
And lets not forget a good IDE has a good editor which lets you rename variables and functions across several files, keep a history of changes, does code completion, shows which functions are in a file, where variables are declared, etc, etc. A good IDE should make dealing with the source code much easier.
<voice=Dave>
No! Noooooo!
</voice>

;D

Emacs uber alles.
 

Offline majorkuso

  • Contributor
  • Posts: 20
Re: Want to learn "C"
« Reply #31 on: October 05, 2012, 11:30:01 pm »
Since you are starting with the arduino I would recommend this book Beginning Arduino Programming by Brian Evans http://www.amazon.com/gp/product/1430237775/ref=ox_sc_sfl_title_4?ie=UTF8&smid=ATVPDKIKX0DER   It contains examples and explains loops easily and if I remember right goes into arrays. I have it and I highly recommend it until you get used to the loops and syntax of the arduino then when you feel you have accomplished it enough you can move on to c or c++ for more power, I have yet to move on due to lack of time to continue, but I am still young so I will learn as I go.
« Last Edit: October 05, 2012, 11:42:07 pm by majorkuso »
 

Offline alan monro

  • Contributor
  • Posts: 17
  • Country: au
Re: Want to learn "C"
« Reply #32 on: October 06, 2012, 03:12:56 am »
Thank you for your trouble , :D
I did not know the book existed  , now I know.
I will certainly purchase it . Thanks.........................Alan
 

Offline Markybhoy

  • Regular Contributor
  • *
  • Posts: 59
  • Country: gb
Re: Want to learn "C"
« Reply #33 on: October 07, 2012, 05:46:47 pm »
Im going to try and learn C and picked up a book that looks good for beginners,  its called C Primer Plus by Stephen Prata.
Its aimed at beginners and I like it because it has loads of exercises at the end of each chapter to practice.

There is also free video training here -  http://www.wibit.net/curriculum/the_c_lineage/programming_in_c

And a free course starting soon from Harvard covers C programming -  https://www.edx.org/courses/HarvardX/CS50x/2012/about
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14441
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Want to learn "C"
« Reply #34 on: October 20, 2012, 11:57:09 am »
If you want to learn C DO NOT touch the arduino! It is a variant and just mess you up when you want to do proper c. I'm awful at programming but ditched my arduino early on and am now using mikroc, it's not perfect but free for home use and usable.
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #35 on: October 20, 2012, 12:48:34 pm »
People keep saying this but i have yet to notice any significant variation. Of course there is the detail that Arduino is actually programmed in C++ so compared to C, yes it varies a lot, but not in an Arduino specific way. As far as i have seen, it is standard C++ as implemented by AVR-g++. All of the Arduino quirks are actually just its standard library functions that anyone can implement, nothing "closed" about those at all. SOme time ago i did a camera dolly controller using Arduino. Not being an Arduino enthusiast as such, i wrote the code in straight C++ with dynamically allocated class instances etc etc and no regard for any "variations" due to it being Arduino. It all worked just as in any other C++ environment. So until proven otherwise, i maintain that Arduino is programmed with straight C++ with a bunch of libraries included in the deal.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9495
  • Country: my
  • reassessing directives...
Re: Want to learn "C"
« Reply #36 on: October 20, 2012, 12:52:57 pm »
If you want to learn C DO NOT touch the arduino!
i agree. but why?
It is a variant and just mess you up when you want to do proper c.
oh here! reason and evidence? and what is the meaning of "proper c"?

i agree that you should not touch arduino when learning C is because arduino is more hardware specific, ie you also need to learn what pins, what definitions and how the mcu functions, which will drag you away from your main() objective.

Quote
It all worked just as in any other C++ environment
if you want C, just use C syntax. if you want C++, you may use C++ syntax, its been like that for centuries.
« Last Edit: October 20, 2012, 01:38:38 pm by Mechatrommer »
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #37 on: October 20, 2012, 01:25:42 pm »
If you want C, just use C syntax. if you want C++, you may use C++ syntax,
Kinda hard to anything else, if you think about it. Actually, if you want C++, you _must_ use C++ syntax - - duh.
Quote
its been like that for centuries.
Yes, it is a commonly known fact that Leonardo da Vinci wrote the first C++ compiler for his wooden Personal Abacus in 1502 while working for the Borgias in Florence, the better to calculate ballista trajectories.

Nothing sings like a kilovolt.
Dr W. Bishop
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9495
  • Country: my
  • reassessing directives...
Re: Want to learn "C"
« Reply #38 on: October 20, 2012, 01:33:24 pm »
If you want C, just use C syntax. if you want C++, you may use C++ syntax,
Kinda hard to anything else, if you think about it. Actually, if you want C++, you _must_ use C++ syntax - - duh.
i dont know which one i used when programming C or C++. i never had issue compiling them with only one compiler, except there will be slight option adjustment and that mysterious "extern C" thing. i guess its like C++ is totally a different thing from C? if that so then yes... arduino is not C, but C++ :D
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #39 on: October 20, 2012, 01:57:05 pm »
You need the "extern C" thing to instruct the compiler to use C calling convention. Among other things, C and C++ do function name mangling differently, C++ to support polymorphism and whatnot, and of course C does not know anything about that.
Afaik Arduino uses g++ by default, so everything is considered C++, although basic statements are identical for C and C++ so it is hard to see the difference right away. Then again, if you compile everything from source, you should not need the extern C pragmas because everything would observe C++ calling conventions naturally. It is only if you have precompiled modules in object format that you need to link to.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Re: Want to learn "C"
« Reply #40 on: October 20, 2012, 04:45:21 pm »
If you try to learn C from, say K&R, on the Arduino, you will run into problems right away. No printf function! Yes, if you know what you are doing, you can work around this with the primitive print function over the port back to your computer, but that's not something I would wish on a beginner learning C from a book...
 

alm

  • Guest
Re: Want to learn "C"
« Reply #41 on: October 20, 2012, 05:04:18 pm »
The lack of interactive debugging might also be an obstacle. It can be very instructive to step through a loop or function call in a debugger and watch all the variables change or go out of scope. Most of the uC development environments feature in circuit debugging, but the Arduino lacks any real debugging support.
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #42 on: October 20, 2012, 05:19:52 pm »
If you try to learn C from, say K&R, on the Arduino, you will run into problems right away. No printf function! Yes, if you know what you are doing, you can work around this with the primitive print function over the port back to your computer, but that's not something I would wish on a beginner learning C from a book...
Sigh. Please try to speak about the right thing. printf() has got nothing to do with C language as such. It is just one of the runtime library functions. Implemented in some environments but not in others. Arduino does not implement it out of the box, but if you want it, just grab the source from somewhere and compile it. Of course you need a file system for printf() to work correctly so next you need to implement that. Wait, no hardware to support storage or text I/O so you need more... but you get the picture. Lack of printf() is not specifically related to C language.
In Arduino you can use the write() and writeln() functions instead. Formatting is different but who cares. You want to print - print it on the PC screen.
The lack of interactive debugging might also be an obstacle. It can be very instructive to step through a loop or function call in a debugger and watch all the variables change or go out of scope. Most of the uC development environments feature in circuit debugging, but the Arduino lacks any real debugging support.
Write and printf are essentially equal for debugging, but neither comes close to a proper debugger. The Arduino IDE is a program development and load environment and imo that is the limit of skills of most Arduino users, who are mostly not "real" programmers. But at least Uno and maybe some others come with the standard ISP header, enabling DebugWire support if you have a suitable debugger, say JTAGICE 2 or some such. Of course that is not part of the free Arduino package. I guess the point is that all toolchains need some kind of hardware support.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9495
  • Country: my
  • reassessing directives...
Re: Want to learn "C"
« Reply #43 on: October 20, 2012, 06:14:43 pm »
i believe there's confusion between C... (1) language set, (2) standard library functions, (3) IDE interface. lets dont talk about how compiler "mangles" things, thats #4. and i wont say much about them except imho, they are 3 distinct entities. lack of (2) and (3) doesnt mean that its not the "language", afaik. if you expect printf to be a C, then how do you expect atMega256 printf something? out of its butt?

want printf? do it on a complete system with monitor or printer, a PC! and a console! but then, you dont expect printf will show you something on a "Windows" what you see on your screen right now. Windowed or mCU peripherals or such for that matter are another whole story not relating to "C", if you expect them to be, than you can buy a train ticket to DissapointmentVille. K&R guide always been for consoled PC such as DOS, so use it and do it there! want to do C for embedded mCU? buy a "C for embedded mCU" book from Mr Ritchie if you can find one.

now, are we talking Arduino "IDE"? well its nothing but to waste people's time, if you got to know it better. lack of debugging tools is one thing, most annoying is how inefficient it makes compilation even for a simple application, its so damned slow. nothing more to say about it.
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14441
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Want to learn "C"
« Reply #44 on: October 20, 2012, 06:45:03 pm »
If you want to learn C DO NOT touch the arduino!
i agree. but why?
It is a variant and just mess you up when you want to do proper c.
oh here! reason and evidence? and what is the meaning of "proper c"?

i agree that you should not touch arduino when learning C is because arduino is more hardware specific, ie you also need to learn what pins, what definitions and how the mcu functions, which will drag you away from your main() objective.

Quote
It all worked just as in any other C++ environment
if you want C, just use C syntax. if you want C++, you may use C++ syntax, its been like that for centuries.

for starters every arduino sketch repeats itself, with c you have to "do something" to make a program loop
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9495
  • Country: my
  • reassessing directives...
Re: Want to learn "C"
« Reply #45 on: October 20, 2012, 06:55:48 pm »
for starters every arduino sketch repeats itself, with c you have to "do something" to make a program loop
are you talking about main()? here i searched for you... check your ...\Arduino\hardware\arduino\cores\arduino folder its main.cpp...
Code: [Select]
#include <WProgram.h>

int main(void)
{
init();

setup();
   
for (;;)
loop();
       
return 0;
}
thats the entry point. doesnt that look like C or something to you? the arduino team has made it easy for you, you dont have to repeat that same "semantics" in your every project file.
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 14441
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Want to learn "C"
« Reply #46 on: October 20, 2012, 06:57:34 pm »
well it depends on what you want the arduino for, if your using it as a base for moving to C you may be learning twice, if you just want to do arduino then go right ahead
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #47 on: October 20, 2012, 07:00:36 pm »
for starters every arduino sketch repeats itself, with c you have to "do something" to make a program loop
And as in any other C or C++ program, it is done in the file main.cpp, that you can in this case find in folder C:\Program Files\arduino<ver>\hardware\arduino\cores\arduino:

#include <WProgram.h>

int main(void)
{
   init();

   setup();
   
   for ( ; ; )
      loop();
       
   return 0;
}


So the setup() and loop() are declared as externals and defined in your application. But it is the (otherwise invisible) main program that does the looping.
« Last Edit: October 20, 2012, 07:02:23 pm by Kremmen »
Nothing sings like a kilovolt.
Dr W. Bishop
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9495
  • Country: my
  • reassessing directives...
Re: Want to learn "C"
« Reply #48 on: October 20, 2012, 07:07:52 pm »
you making duplicate post Kremmen ;) next exercise... find the init() :D
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #49 on: October 20, 2012, 07:14:50 pm »
Oh, right. Didn't see that before posting.

init() is declared in wiring.h and defined in wiring.c.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 9630
  • Country: us
Re: Want to learn "C"
« Reply #50 on: October 20, 2012, 07:23:52 pm »
Sigh. Please try to speak about the right thing. printf() has got nothing to do with C language as such.

However, printf() is part of the standard library and along with the rest of the standard library is described precisely by the language standard. A standard-conforming C implementation is expected to provide the standard library exactly as specified. If you have a C compiler without all the components defined by the language standard you don't have a proper C environment and you can't follow examples from a C tutorial.

As has been stated above, this is something that experts may understand and take in their stride, but it is something that may be confusing for a beginner. If you cannot pick up a copy of K&R and work through all the examples and exercises as given, you don't have a working C environment.
I'm not an EE--what am I doing here?
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #51 on: October 20, 2012, 08:01:15 pm »
Well. printf() comes as a standard in some environments and not in others. It is a library function and has zip to do with the core language definition. It is included in environments that naturally support files and streams. Also,and perhaps mor to the point, it has zip to with the compiler, exactly because it is not a builtin language construct, but a _library_ _function_. Someone long ago decided that it would be nice to print things on console and into files and included that in the stdlib and yes, in the part of standards describing stdlib. But if you don't have a console and don't have a file system, printf() is about as useful as the pope's balls. That's why you seldom find it in an embedded development environment.

K&R is a good if old source (it does not describe the current C standard) and its examples reflect that fact. But if you sorely must have printf() in Arduino to run the examples, there is no technical reason why it cannot be done. It will be needlessly wasteful of the meager resources but it definitely can be done.

I disagree with your last statement. Presence of printf() in stdlib does not define a working C environment. In fact i am not sure if all the K&R examples would even compile as written, using a recent (say C99 or newer) standard compiler. But i haven't checked and don't really care.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline JuiceKing

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Want to learn "C"
« Reply #52 on: October 20, 2012, 09:35:30 pm »
Sigh. Please try to speak about the right thing. printf() has got nothing to do with C language as such.

However, printf() is part of the standard library and along with the rest of the standard library is described precisely by the language standard. A standard-conforming C implementation is expected to provide the standard library exactly as specified. If you have a C compiler without all the components defined by the language standard you don't have a proper C environment and you can't follow examples from a C tutorial.

As has been stated above, this is something that experts may understand and take in their stride, but it is something that may be confusing for a beginner. If you cannot pick up a copy of K&R and work through all the examples and exercises as given, you don't have a working C environment.

Exactly.
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1119
  • Country: fi
Re: Want to learn "C"
« Reply #53 on: October 20, 2012, 10:00:52 pm »
A standard-conforming C implementation is expected to provide the standard library exactly as specified.
That's true of hosted implementations. Freestanding implementations only have to provide <float.h>, <limits.h>, <stdarg.h>, <stddef.h>, <iso646.h>, <stdbool.h> and <stdint.h>.

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3141
  • Country: us
Re: Want to learn "C"
« Reply #54 on: October 21, 2012, 02:32:02 am »
And in fact arduino has printf() (or will allow you to use printf()), but you'll have to set it up in mysterious ways before you can use it (sort of like using JCL to define the IO of your ForTran programs on the IBM mainframe.)

Look, there are about three pieces...

1) There is the syntax of the C language itself.  Syntax, Functions, Variables, control statements, operators, and so on.  This is probably best learned on a desktop, with a debugger handy, using a reference like K&R.  There are a bunch of principles here common to many computer languages.  If you've programmed in any other language before, or had one of the "Computer Science 101" classes, this should not be all that strange.  If you don't have ANY programming background, you might want to look around for a basic programming or computer science class (exact language not too important.)  Be aware that many classes, and books, jump right into manipulation of images on your desktop screen, because that's the fun part.

2) There are a bunch of concepts that are key to programming microcontrollers that aren't so common in desktop environments.  IO Registers.  Bit Masks vs bit numbers, bit shifting, and bit-banged IO.   Volatile variables.  Memory limitations.  Interrupts.  Concurrency (and the lack thereof.)  The low speed of some peripherals.  Locations that you write a 1 to to set them to zero.  What peripherals do and what are their limitations.  The fact that exit() isn't going to stop your program, and terrible bugs aren't going to put a nice error message on your screen.
This is probably the hardest part.  If you have a chip/electronics/assembler background, it's not too difficult to add to the basic C knowledge, but books and tutorials that deal with these things are a lot rarer than books on Excel...

3) A particular environment will have a set of library functions that it uses for doing environment-specific things.  This is true whether you're talking about Standard C functions like printf(), Posix functions (an operating system standard), arduino, cmsis, Atmel Software Framework, Stellarisware, or whatever.  Arduino gets some negative press for "hiding important things that you should learn", but I don't see that it's that much different than vendor-provided libraries.  (A vendor training video I watched recently had a sample program that used both LED_Toggle(LED0) and gpio_toggle_pin(NHD_blahblah_BACKLIGHT).  Both to blink LEDs...)  Arduino uses the same standard avr-libc that most people programming AVRs in C end up using, and adds some additional functions.
A lot of "modern" programming seems to be about learning what library functions exist, and how to get them and use them.  Cause those GTK windowing classes are so much more advanced than the KDE `toolkits, you know.  (not that this is really "modern"; back in the Fortran/COBOL/PL1 days, a lot of learning a language was about using the IO facilities of the language.  But in those days those were part of the language, while now you can pick and choose different libraries that behave somewhat differently.)

And that will get you started.  You still won't be able to immediately connect up that weird 9 DoF sensor chip and make an autonomous quadcopter assassin-bot, because you'd need to understand how that chip works (unless someone else has already done it and is willing to share their code, which is somewhat more likely in the arduino world than anywhere else these days.)  And even after you've done that, autonomous robot assassins are hard research projects that DoD pays large teams big bucks to try to figure out...

Quote
A standard-conforming C implementation is expected to provide the standard library exactly as specified.
And one of the first things you need to learn if you want to program C on microcontrollers is that that isn't how it's going to be.

Quote
In Arduino you can use the write() and writeln() functions instead.
print and println class methods, actually (so "Serial.print(...)" rather than just "print(...)")
(writeln is Pascal...)
« Last Edit: October 22, 2012, 07:34:31 am by westfw »
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1283
  • Country: fi
Re: Want to learn "C"
« Reply #55 on: October 21, 2012, 07:10:58 am »
[...]
print and println class methods, actually (so "Serial.print(...)" rather than just "print(...)")
(writeln is Pascal...)
And so it is of course :) I'm confusing Arduino and Delphi Pascal here, i see. Been doing Delphi in the past and still consider that a gentleman's environment, however out of the picture it may be in these Java days.
Otherwise your post reflects my thoughts precisely.
Nothing sings like a kilovolt.
Dr W. Bishop
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf