Talk About Network

Google





Programming > C - C++ Learning > Re: Using the s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 22 Topic 4074 of 4400
Post > Topic >>

Re: Using the same source file from other source files

by Hal Vaughan <hal@[EMAIL PROTECTED] > Mar 20, 2008 at 07:29 AM

Richard Heathfield wrote:

> Hal Vaughan said:
> 
>> I know I saw the answer to this in a FAQ somewhere in the past week or
>> two, but now tat I need to know it, I can't find which FAQ it was in.
>> 
>> I have a program that's grown to several files and I was compiling it
by
>> just using #include where necessary
> 
> Hal, you need to find yourself a large hammer, preferably one with
> "ANAESTHETIC" written along the side...       :-)

Yeah, the problem is I kind of hit the ground running and this is my
"intro"
project to the language and I'm squeezing it in between others, so I'm
reading as much as I can, but that means there's holes in what I pick up. 
I'm just now getting to compiling info other than just "g++ -o myprog
myprog.cpp"

> Never use #include for source (admittedly for certain values of "never",
> but this is something that expert programmers are very loathe to do
except
> on very special occasions. You may deduce that newbies should not be
doing
> it *at all* - and it's certainly not necessary for them to do so).

Okay, gotcha.  I'm finding out people in this group tend to have a higher
standard in many ways than elsewhere, which helps because I learn why
something isn't a good idea, even if "everyone else" is doing it.

>> How can I make sure several files can access the functions in a
separate
>> file without getting repeated definitions?
> 
> In the source, you simply declare (but not define) the functions in a
> header, and #include the header into the sources that need to call those
> functions (and the source that defines them, as a safety check).

So I create protofunctions in a header and include that instead of the
actual source file, right?


> To make the files all work together, you have to "link" them.
> 
> In gcc, it works like this:
> 
> gcc ...lots of flags and stuff... -c -o foo.o foo.c
> gcc ...lots of flags and stuff... -c -o bar.o bar.c
> gcc ...lots of flags and stuff... -c -o baz.o baz.c

For some reason when I try gcc, I run into problems, so I've been using
g++. 
I know it's to the same binary, but for some reason it only works as g++.
Are there implications to that which aren't obvious?

> -c means "just compile, don't try to link", and translates source files
to
> object files, but you don't get a program yet...
> 
> gcc ...lots of flags and stuff... -o myprog foo.o bar.o baz.o

Okay, I was trying that, but without any header files with function
declarations.  That's what I was missing!

> ...and now you link the object files together to get a program called
> myprog.
> 
> But having said that, you're probably using an IDE, and nowadays you may
> well find that drag n' drop works just fine. :-)

I've installed the C and C++ stuff in Eclipse, but I've been using a text
editor and the command line for now, while I'm getting use to it.  Eclipse
needed a make file and now that I'm finally building one, I may switch
over
to it.  For me, just being able to find functions and refactor is a huge
help in itself!

Thanks!

Hal
 




 22 Posts in Topic:
Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 07:10:47 
Re: Using the same source file from other source files
Richard Heathfield <rj  2008-03-20 07:25:59 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 07:29:28 
Re: Using the same source file from other source files
"Jim Langston"   2008-03-20 00:55:37 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-20 15:31:49 
Re: Using the same source file from other source files
Richard Heathfield <rj  2008-03-20 08:36:26 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 08:50:25 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 09:28:25 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 09:37:01 
Re: Using the same source file from other source files
"Chris ( Val )"  2008-03-21 03:37:07 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-25 17:22:35 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 15:08:23 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 15:37:26 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 15:48:02 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 15:56:20 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-20 17:11:20 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 17:54:57 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-21 10:03:58 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 19:34:41 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 20:31:21 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 19:45:49 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 20:34:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 9:21:04 PST 2009.