Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Learning process

Reply
Thread Tools

Learning process

 
 
Karsten Kvistad
Guest
Posts: n/a
 
      01-03-2004
Hi!
I'm currently teaching myself the C programming language. The problem is
I don't know what to do next. I know file I/O, pointers, functions and
the like. I do not know how to make .h files, Makefiles or anything else
required for large projects. Should I learn how to do this, sockets,
GTK, curses or what?

--
(o_ Confused,
(/)_ Karsten Kvistad
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      01-03-2004
Karsten Kvistad <karsten-k.broadpark@no> scribbled the following:
> Hi!
> I'm currently teaching myself the C programming language. The problem is
> I don't know what to do next. I know file I/O, pointers, functions and
> the like. I do not know how to make .h files, Makefiles or anything else
> required for large projects. Should I learn how to do this, sockets,
> GTK, curses or what?


Well, .h files are syntactically identical to .c files. The only thing
that is usually different is that .h files should not contain any actual
executable code, only definitions.
Makefiles are not really a C concept. Make is a tool for compiling or
building just about anything. I've used it to make LaTeX documents. You
don't have to use make to compile C. Especially single source file
programs can be compiled just fine with one compiler call.
If I were you I'd look into .h files and makefiles first. Sockets, GTK
and curses are not part of C, they're platform-specific add-ons. It's
important to understand the language itself before tackling those.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am lying."
- Anon
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      01-03-2004
Karsten Kvistad wrote:

> Hi!
> I'm currently teaching myself the C programming language. The problem is
> I don't know what to do next.


One thing you might want to do before too long is to check that your teacher
knew what he was talking about.

This newsgroup can help you do that.

> I know file I/O, pointers, functions and
> the like. I do not know how to make .h files,


Most people use a text editor for this. More importantly for you to
discover: what /is/ a header?

Answer: a header is an interface description for a module. Now that you know
that, what do you think belongs in a header?

--
Richard Heathfield : http://www.velocityreviews.com/forums/(E-Mail Removed)
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
 
Reply With Quote
 
Karsten Kvistad
Guest
Posts: n/a
 
      01-03-2004
Richard Heathfield wrote:
> Karsten Kvistad wrote:
>>I know file I/O, pointers, functions and
>>the like. I do not know how to make .h files,

>
> Most people use a text editor for this.


I figured so... I meant that I don't know what should go into them.

If this was a joke, I apologise for my lack of insight
--
(o_ Karsten Kvistad
(/)_
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      01-03-2004
Karsten Kvistad <karsten-k.broadpark@no> scribbled the following:
> Richard Heathfield wrote:
>> Karsten Kvistad wrote:
>>>I know file I/O, pointers, functions and
>>>the like. I do not know how to make .h files,

>>
>> Most people use a text editor for this.


> I figured so... I meant that I don't know what should go into them.


> If this was a joke, I apologise for my lack of insight


You figured correctly, they are made with a text editor. See my previous
post for an answer to your additional question. Basically, put the
following in .h files:

* Macro definitions
* Structure and union definitions
* Typedefs
* Extern function or variable declarations

....and *very* little else. Especially, do NOT put any real definition
of a variable or function, that would actually take up space in the
object file. That would only cause linking problems if you happen to
#include the same .h file from two .c files.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
 
Reply With Quote
 
Morris Dovey
Guest
Posts: n/a
 
      01-03-2004
Karsten Kvistad wrote:
> Hi!
> I'm currently teaching myself the C programming language. The problem is
> I don't know what to do next. I know file I/O, pointers, functions and
> the like. I do not know how to make .h files, Makefiles or anything else
> required for large projects. Should I learn how to do this, sockets,
> GTK, curses or what?


Karsten...

In brief, header (.h) files are repositories for information
about code and data in your translation unit that you choose to
make available to other translation units.

Generally this information consists of declarations (not
definitions!) and descriptive comments to help others understand
what and why you've included in the header.

Makefiles, sockets, GTK, curses, and any 'what' that aren't
actual elements of the C language can and should be addressed in
other newsgroups. My <off-topic> suggestion would be to learn to
use the make utility as early as possible - doing so may
facilitate your efforts with all of the subjects you seem
interested in investigating. </off topic>

The "what to do next" answer will be highly dependent on your
personal interests. You're on a voyage of discovery - look
around, explore, investigate, take time to play, tinker, and
experiment...

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      01-03-2004
osmium wrote:
> Richard Heathfield writes:
>
> > Answer: a header is an interface description for a module. Now
> > that you know that, what do you think belongs in a header?

>
> I think it would be more accurate to say "A header often contains
> an interface description for a module".


IMO if it contains anything more it is being misused.

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      01-03-2004
Richard Heathfield writes:

> Answer: a header is an interface description for a module. Now that you

know
> that, what do you think belongs in a header?


I think it would be more accurate to say "A header often contains an
interface description for a module".


 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      01-03-2004
CBFalconer <(E-Mail Removed)> writes:

> osmium wrote:
> > Richard Heathfield writes:
> >
> > > Answer: a header is an interface description for a module. Now
> > > that you know that, what do you think belongs in a header?

> >
> > I think it would be more accurate to say "A header often contains
> > an interface description for a module".

>
> IMO if it contains anything more it is being misused.


What do you think of inline functions?
--
"I ran it on my DeathStation 9000 and demons flew out of my nose." --Kaz
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-03-2004
Karsten Kvistad wrote:

> Richard Heathfield wrote:
>> Karsten Kvistad wrote:
>>>I know file I/O, pointers, functions and
>>>the like. I do not know how to make .h files,

>>
>> Most people use a text editor for this.

>
> I figured so... I meant that I don't know what should go into them.
>
> If this was a joke, I apologise for my lack of insight


Er, yes, it was, but the rest of my article was intended seriously.

Just to give you a simple idea of what might go into a header, take a look
at:

http://users.powernet.co.uk/eton/c/fgetdata.h
http://users.powernet.co.uk/eton/c/fgetword.c
http://users.powernet.co.uk/eton/c/fgetline.c

(fgetword() reads an entire word of text, no matter how large, into a
buffer, resizing the buffer as necessary. fgetline() does the same for
lines.)

To use these functions, the programmer must #include "fgetdata.h" - but what
is /in/ fgetdata.h? Let's see...

Well, okay, there's a huge comment at the beginning. We'll skip over that,
and then we find this:

#ifndef FGETDATA_H_ /* See Note A */
#define FGETDATA_H_ 1 /* See Note A */
#include <stdio.h> /* See Note B */

/* Next three lines: See Note C */
#define FGDATA_BUFSIZ BUFSIZ /* adjust to taste */
#define FGDATA_WRDSIZ sizeof("floccinaucinihilipilification")
#define FGDATA_REDUCE 1

/* This space intentionally left blank -
See Note D */

int fgetline(char **line, size_t *size, size_t maxrecsize, FILE *fp,
unsigned int flags); /* See Note E */
int fgetword(char **word, size_t *size, const char *delimiters, size_t
maxrecsize, FILE *fp, unsigned int flags); /* See Note E */

#endif /* See Note A */

Note A: the header is protected by "inclusion guards". These stop the
header's main contents from being copied ad nauseam into a translation unit
if it happens to have been #included a bit too enthusiastically. Working
out how it works is diverting, and shouldn't take you more than 2 minutes.

Note B: Since the header refers to the FILE type, it's a good idea to
include the necessary header for that type. This means your calling code
doesn't have to remember to #include <stdio.h> before #including /this/
header.

Note C: Symbolic constants that you want to make available to the caller can
go here, as shown.

Note D: This module didn't need any new types. If you had any, you'd want to
define them here.

Note E: Function prototypes. These are perhaps the most easily-recognised
constituents of a header.

That's pretty much all I put in headers, really - comments, preprocessing
directives, typedefs, and function prototypes. I see no reason to clutter
them up with other stuff (on the whole). If you're heavily into global
data, though, you'll want to put your external declarations (NOT the
definitions) in a header too. (I'm /not/ heavily into global data.)

--
Richard Heathfield : (E-Mail Removed)
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[I'm learning C]: Learning to use ucontext Andrey Popp C Programming 5 01-31-2012 01:05 AM
need info on MAC learning process cheeku Cisco 4 05-23-2007 11:52 AM
Learning C and Learning Make/Configure/Building/Linking Hal Vaughan C Programming 7 03-21-2006 05:07 PM
e-learning, (collaborative learning environment) collinm Java 1 09-08-2005 09:52 PM
language learning vs. process Ryan Walker Python 7 12-03-2003 12:34 AM



Advertisments