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

0 Members and 1 Guest are viewing this topic.

Offline glee

  • Contributor
  • Posts: 36
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: 895
  • 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: 242
  • 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: 1289
  • 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: 27882
  • 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: 895
  • 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 monroTopic starter

  • 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: 18022
  • 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: 1289
  • 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
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • 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 »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1289
  • 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
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • 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
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1289
  • 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: 1289
  • 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
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • 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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18022
  • 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
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • 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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18022
  • 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: 1289
  • 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
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • 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
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1289
  • 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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf