TheArch1tect
Posts: 17
Joined: Tue Dec 11, 2012 3:20 am

Questions about implementing C

Thu Mar 27, 2014 2:30 am

Hello all,


I am currently a college student taking a class in C. I purchased a Pi a while back, and I would like to try to implement the (very simple) programs I am writing in class onto the Pi. However, I am having a difficult time figuring out exactly how to do this; I have no programming experience of any sort.

If I remember correctly, I'm using Rasbian right now (I can definitively check later). I've already gotten the Pi up and running (with identically configured cards for different projects), but I can't figure out where I need to stick code... as dumb as that makes me feel. I think the code I have access to right now is Python, and I'm under the impression that sticking C into it would be as useful as sticking diesel into a gas operated car. Therefore, I'm assuming I need a different OS or some way to implement C.

I'm not sure if I should be posting this under the 'Beginner' section of the forums, so let me know if I need to redirect my questions.


Thanks in advance,
-Arch

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Questions about implementing C

Thu Mar 27, 2014 2:45 am

Hi Arch,
TheArch1tect wrote:However, I am having a difficult time figuring out exactly how to do this;
Luckily, there are several tutorials available... You can start with this one: https://www.cl.cam.ac.uk/projects/raspb ... intro.html
TheArch1tect wrote:I have no programming experience of any sort.
What counts is a will and willingness to invest some time in learning.
TheArch1tect wrote:Therefore, I'm assuming I need a different OS
...wrong assumption.
TheArch1tect wrote:let me know if I need to redirect my questions.
No need to redirect the questions... power-on the RasPi and start googling instead.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: Questions about implementing C

Thu Mar 27, 2014 8:26 am

I've been playing with python on my Pi, but am probably headed towards C. I have some sympathy for OP, documentation can be hard to find, albeit that Cambridge article is superb. I like the way it seems to apologise for some of the amazingly idiosyncratic things you have to take on board to get C working, eg

Unlike in C source files, in a makefile the TAB key is not completely ignored. The line following a target MUST begin with (and only with) a tab. [… it gets worse!]. (If a space is mixed up in there then make will return a '***missing separator' error). This line gives make the command to run when the target is to be re-made. Note that this line is the same as those used to run gcc directly from the command line.zz

Gosh! Given that tabs and spaces look identical on screen, what a pit to dig for the unwary! (contemporary Python, amazingly incorporates the same mantrap)! Against this, C is wonderfully explicit in its {…}s and explicit ';'s only to drop these in some of the support structures. They do say a camel is an animal designed by a committee?

Anyway, thats how it is, it ain't gonna change and you just have to learn it. Don't courses teach such matters any more? Sorry to rant a bit :D

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Questions about implementing C

Thu Mar 27, 2014 8:46 am

If I were a complete programming beginner, I would give Python a really good go first.

C can be a bit daunting I would think to someone completely new to programming. In C, stuff that is easy in python is difficult, so it can be detrimental to the learning process. Of course, it does mean that when you move to C from Python (usually for speed purposes), there is another learning step - how to do stuff the was previously easy!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: Questions about implementing C

Thu Mar 27, 2014 9:37 am

Absolutely wrt "learning go program", Jamie.

I've been tapping in code since 1976 (punched cards, even)) Yet I still find the C implementation (eg make file above, totally different syntax rules) a bit daunting!

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Questions about implementing C

Thu Mar 27, 2014 10:05 am

chrisryall wrote:Absolutely wrt "learning go program", Jamie.

I've been tapping in code since 1976 (punched cards, even)) Yet I still find the C implementation (eg make file above, totally different syntax rules) a bit daunting!
It's a real shame that C almost always requires make files, because those things suck. Been using C for 25 years, and still cannot write a vaguely complex makefile from scratch. Horrible things. Even the efforts to make things better (Cmake etc) are still fairly horrible. I suppose IDEs like VS and Eclipse have helped.

James
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Questions about implementing C

Thu Mar 27, 2014 10:23 am

Um, I don't see the connection between C and make.

Anymore than I see a connection between C and (insert name of your favorite editor here).

Some (obvious) notes:

1) You can use make with any tools that make one sort of file from another sort. I've written systems built around make that don't use C at all. In any case, I don't see how you can say "If you use C, you pretty much have to use make…"

2) It's not like any other system has the same sort of functionality (the basic "to make this file from that file, run this command - and only do the command if you need to - i.e., based on the file date/timestamp" functionality). And those that do, end up looking a lot like make.

3) The "tab" thing. Like everything else in Unix/C, you get used to it. Get over it. And besides, if you like Python, you should love make.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23083
Joined: Sat Jul 30, 2011 7:41 pm

Re: Questions about implementing C

Thu Mar 27, 2014 10:59 am

Joe Schmoe wrote:Um, I don't see the connection between C and make.

Anymore than I see a connection between C and (insert name of your favorite editor here).

Some (obvious) notes:

1) You can use make with any tools that make one sort of file from another sort. I've written systems built around make that don't use C at all. In any case, I don't see how you can say "If you use C, you pretty much have to use make…"

2) It's not like any other system has the same sort of functionality (the basic "to make this file from that file, run this command - and only do the command if you need to - i.e., based on the file date/timestamp" functionality). And those that do, end up looking a lot like make.

3) The "tab" thing. Like everything else in Unix/C, you get used to it. Get over it. And besides, if you like Python, you should love make.
Whatever. The vast majority of C projects I have been involved with in the last 25 years have used makefiles. The vast majority of OSS C projects use make or similar. The Linux kernel uses make. And clearly make can be used for other languages apart from C, my point was that, as stated, most C projects use make of one form or another. And the make syntax is as ugly as hell, and pretty much incomprehensible to all but make experts.

Python projects doesn't use make, do they?

3) What tab thing?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Questions about implementing C

Thu Mar 27, 2014 11:49 am

make without a makefile works great.

create helloworld.c

then type make

make is great stuff

http://www.raspberrypi.org/phpBB3/viewt ... le#p478319.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Questions about implementing C

Thu Mar 27, 2014 12:25 pm

And the make syntax is as ugly as hell, and pretty much incomprehensible to all but make experts.
I've never had a problem with it - and I'm no expert (on make or anything else…)
Python projects doesn't use make, do they?
They could. I assume that anything that involves "separate compilation" (in any form) could use make. I think youtube-dl does...
3) What tab thing?
The main beef in this thread seems to be the requirement that "rule lines" start with a tab.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

SteveSpencer
Posts: 351
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK

Re: Questions about implementing C

Thu Mar 27, 2014 2:02 pm

If you use a proper editor, it has a mode where you can see non-printing characters.
In vi, some implementations allow you to use ':set list' and ':set nolist' for just such eventualities.

Failing that, od -c is a good bet :geek:
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...

TheArch1tect
Posts: 17
Joined: Tue Dec 11, 2012 3:20 am

Re: Questions about implementing C

Sun Mar 30, 2014 9:28 pm

Wow, thank you all for the quick replies. It'll take some time for me to sort through all, but that Cambridge article looks like it'll be a great start.

-Arch

Edit: In fact, the Cambridge article was exactly what I was looking for. Thanks again!

Heater
Posts: 12976
Joined: Tue Jul 17, 2012 3:02 pm

Re: Questions about implementing C

Mon Mar 31, 2014 8:01 am

There is no connection between C and make.

Well, except 99.9% of every C/C++ project is built using make.

I happy to create make files for my own simple projects.

When working on huge multi-man projects I've noticed they generally have one guy as the "make expert" who spends half his time creating and maintaining the build system. No one else will dare touch it. That's how horrible make can become.

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: Questions about implementing C

Mon Mar 31, 2014 8:12 pm

Oh, much worse .. the "make" expert gets flu

. … or gets poached by a competition company ;)

Do the big chip makers still manufacture "write only memory"? :D

User avatar
Redrobes
Posts: 80
Joined: Mon Dec 26, 2011 9:19 pm
Location: S.W. UK
Contact: Website

Re: Questions about implementing C

Mon Mar 31, 2014 10:31 pm

The main reason makefiles are so incomprehensible is that there is usually only that one guy who knows what hes doing and the rest just take another makefile and hack it about a bit without knowing exactly what they are doing.

Make the syntax is bloody awful but then its still the best language for building command line stuff. The tab and all of the rule set stuff with funny characters is what does it and it does need a bit of head scratching at first but then after a bit you see how powerful it is. The only other language that is popular and declarative is Prolog and thats not all that popular either. No, the main reason people don't like make is that its a declarative language but that's its huge strength. Basically, once you grok it then you cant see the benefit of doing it a whole different way.

There is no tie in between make and C. The reason make is used on 99% of C programs is purely that its the best tool for the job. Most people dont like make syntax but remember that 99% of C project creators thought that it was the best thing at the time.

I use make for all sorts of non programming things now too. My personal opinion is that you need to be good with at least one declarative language in your toolbox. GNU Make is it for me since its very stable and installed on almost every *nix machine under the sun - unlike Prolog or any other you could care to mention.

You could write a simple batch file or other script to do a simple build but when they get large and complex then only at that point, which may be too late, will you discover why scripts are not a good idea for complex builds.

ashby
Posts: 2
Joined: Mon Jun 17, 2013 4:42 pm

Re: Questions about implementing C

Thu Apr 03, 2014 5:38 am

Most of my friend told that it is hard to learn code. Yes It is hard to learn and I am agree with them because they are not interested to spend lot of time on it. I always say to people that, the key to advancing your programming skills is to let go of the tutorial and start your own, self-directed programming project.

Return to “C/C++”