You are not logged in.

#1 2012-01-12 16:56:32

damicore
Member
Registered: 2009-12-21
Posts: 19

[C][NEWBIE] How to get back on track with C and a couple of questions.

Hi there.
I've tried learning C/C++ in the past and I failed because it couldn't hold my interest, books don't seem to have answers to some questions:
How does a header file interact with a binary file? Like in let's say: system apis. They're compiled binaries and the only source code you have are the header files that are full of empty function declarations yet you can call the fuctions from your code. How do they work? Most books just tell you to #include some header file but the way the preprocessor finds those header files and the way those header files interact with the binaries is nowhere to be found. It's just like a magical thing: "just #include this and call that function over there, don't ask how it works, please".
How does ram work? How can I access ram outside of the reach of my program, other daemon's allocated ram, and interact with it, fiddle with it?
How can I learn about this kind of stuff? More thoughtful, lower-level programming. The general know-hows of programming and the way operating systems works/interact with the hardware is what interests me.
I'd like to be able to tweak my driver's source code one day and most books seem kind of geared towards way too high level programming.
I need to learn C almost all over again, at least its syntax and particular rules. I remember what variables, constants, functions, arrays, pointers, etc are supposed to be, at least conceptually.
What are some good webs/books/blogs/forums to start learning C, lower level programmign, etc?

Offline

#2 2012-01-12 17:17:15

GogglesGuy
Member
From: Rocket City
Registered: 2005-03-29
Posts: 610
Website

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

damicore wrote:

Hi there.
I've tried learning C/C++ in the past and I failed because it couldn't hold my interest, books don't seem to have answers to some questions:
How does a header file interact with a binary file? Like in let's say: system apis. They're compiled binaries and the only source code you have are the header files that are full of empty function declarations yet you can call the fuctions from your code. How do they work? Most books just tell you to #include some header file but the way the preprocessor finds those header files and the way those header files interact with the binaries is nowhere to be found. It's just like a magical thing: "just #include this and call that function over there, don't ask how it works, please".

http://www.lurklurk.org/linkers/linkers.html

Offline

#3 2012-01-12 20:11:54

damicore
Member
Registered: 2009-12-21
Posts: 19

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

Thanks for the link, I'll give it a read.

Anything else? Something more about low level C? A book about C programming but more Linux oriented? Explaining debug in gcc (gdebugger was it?) and interaction between daemons, OS structure, etc?

Tutorials on C?

I read the stroustrup C++ book about 2 years ago, may be more.

Last edited by damicore (2012-01-12 20:12:51)

Offline

#4 2012-01-12 20:25:54

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

It's not C, but you may be interested in this excellent online book:
The Art of Assembly Language Programming

I found it excellently written, and very informative.  If you get through all of the material there, you might find answers to many of your questions.  While it does not provide C code, or describe how such things are done in C, if you understand the concepts presented in the book, it should be much easier to understand how it would be done in C, and what to google for to find the relevant C syntax.

EDIT: as this thread has found new life, I'll update the url as it seems the previous one has been taken down:
http://cs.smith.edu/~thiebaut/ArtOfAsse … ofAsm.html

Last edited by Trilby (2013-03-03 16:02:27)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Online

#5 2012-01-12 20:45:26

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

Kernighan & Ritchie

mod edit: Removed link to illicitly distributed copyrighted material. Forum Etiquette: Legality --fsckd

Last edited by fsckd (2012-01-16 17:57:25)

Offline

#6 2012-01-12 21:07:42

damicore
Member
Registered: 2009-12-21
Posts: 19

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

Does K&R talk about any of the topics I posted? I have the feeling it's something as stroustrup's c++ but for C which is not too encouraging. At least from the bits I read from that book back in the day.

Offline

#7 2012-01-12 21:21:53

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

damicore wrote:

Does K&R talk about any of the topics I posted? I have the feeling it's something as stroustrup's c++ but for C which is not too encouraging. At least from the bits I read from that book back in the day.

Well, when you say things like "What are some good webs/books/blogs/forums to start learning C, lower level programmign, etc?" you're kind of leaving it open. Certainly if you want to know C, I have trouble seeing why you would dismiss a classic like K&R.

Offline

#8 2012-01-12 21:58:44

draugdel
Member
Registered: 2008-08-12
Posts: 44

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

http://lwn.net/Kernel/LDD3/ Linux Device Drivers ... but the things you ask about are not really NEWBIE things.

Offline

#9 2012-01-12 22:26:52

damicore
Member
Registered: 2009-12-21
Posts: 19

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

They may not actually be NEWBIE things but I'm a newbie at C (although I understand the basics of the philosophy of C) because of the fact I forgot many things about its syntax.
When I started learning C++ I lost interest because the projects in which I could work where mostly reduced to stdio functions and not much more and stroustrup's book didn't set the bases of interaction with libraries that well (and I think K&R doesn't teach you any of that either).

I want my first project (as of now) to be a fork of DWM or something like that and I plan to start by adding more suport to urgent windows and popups since I never liked the way any linux window manager coped with my IM programs: I often forgot to answer to my friends because all it would do is play a way too unaudible sound file and may be, in SOME wms the taskbar icon would change its color a bit. I'd like to make the icon in the task bar tilt until I open the said urgent window.
Those are my ideas for starters, I don't plan on getting too hardcore from the very beggining but I do want to know more about handling libraries and the way they work for starters.

Last edited by damicore (2012-01-12 22:28:42)

Offline

#10 2012-01-12 23:10:18

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

I found it rather unconventional, but I bought Head First C and I kind of like it.  I have K&R too, but as many say, for a first book on C I agree it might not be the best choice.  But I refer to it more and more often.

Offline

#11 2013-03-03 13:09:50

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

Ooh, what a fun topic!

It's strange, I think I know the answer to all of your questions in the original post but I can't remember where I learned them. I think it was just a gradual process, starting with learning the basics. Do you have a solid understanding of the basics of C programming?

I think the best place to get answers to your questions is to ask them one by one, either here or on Stack Overflow (after searching to see if someone already asked that question first, of course).

Also, I noticed you mention both C and C++. They are very different languages that I feel too many people lump together. So make sure you are clear about which language you want to learn about (which in this case was obviously C).

EDIT: Crap! I just realized this thread is from 2012. I thought it said January 2013. sad

Last edited by drcouzelis (2013-03-03 13:11:33)

Offline

#12 2013-03-03 14:01:13

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

drcouzelis, I didn't notice either until I read your post. Fear not, this is a good, timeless topic. I'm leaving it open. smile


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#13 2013-03-06 13:19:05

Odaer
Member
Registered: 2010-08-14
Posts: 87

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

For intro books I like
"Accelerated C++" for c++
"C programming a modern approach" for C
I have no idea if its the best books out there but I liked them.
For intro C tutorial I think this look resonable and funnier than most tutorial out there http://c.learncodethehardway.org/book/ but I have not tried it.

Last edited by Odaer (2013-03-06 13:19:54)

Offline

#14 2013-03-06 14:15:41

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,347

Re: [C][NEWBIE] How to get back on track with C and a couple of questions.

I don't have any book recommendations beyond K&R, but....

The .h files are really a contract, a description of what is in the libraries.  They describe the interface to the library that the library promises to support.  You include the .h files in your code so that the compiler is aware of how to call the things in the library.  The compiler leaves placeholders to the actual library calls that have to be resolved before the program can run.

Latter, either at compile time (for static libraries) or at run time (for dynamic libraries) the linker (for static libraries) or loader (for dynamic libraries) attempt to resolve the placeholders left by the compiler.  When they are all resolved, the program may run.  If they cannot be resolved, for example if the header file does not accurately represent what is in the library, then you will get an error having to do with unresolved externals.

How does ram work?

Ans:  Very well.  tongue

You might want to read up on Memmory Management Units.  In general, user space programs cannot access memory that does not belong to them;  attempting to do so results in a segmentation fault.  Inter-process communication uses concepts like pipes and semaphore.   Google those keywords and see what you find.

Last edited by ewaller (2013-03-06 14:31:50)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB