By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Include custom libraries

compman9902
100+
P: 105
Hello, and thank you for viewing this post.
I was just wondering how to make includes for programs (includes like iostream.h, except custom)

I have a few functions that I would like to have in my programs with out adding on a few thousand lines of code, so any help would be great. The only problem is (other then having to idea on how to make includes) is that the functions that I want to make into an includable file need incliudes to run, so, how would I do this??
Jun 17 '07 #1
Share this Question
Share on Google+
6 Replies


Savage
Expert 100+
P: 1,764
Hello, and thank you for viewing this post.
I was just wondering how to make includes for programs (includes like iostream.h, except custom)

I have a few functions that I would like to have in my programs with out adding on a few thousand lines of code, so any help would be great. The only problem is (other then having to idea on how to make includes) is that the functions that I want to make into an includable file need incliudes to run, so, how would I do this??
Create a *.h file containing your functions with other includes.

After that just add your won custom include using "name.h" instead of <name.h>

Savage
Jun 17 '07 #2

compman9902
100+
P: 105
Create a *.h file containing your functions with other includes.

After that just add your won custom include using "name.h" instead of <name.h>

Savage
How will the function know what the name of the new variable is?
such as this:
Expand|Select|Wrap|Line Numbers
  1. exampleFunction(string)
  2. {
  3. string = otherExample;
  4. }
  5.  
will that work for displaying the string that the user sends to the function?
Jun 17 '07 #3

Savage
Expert 100+
P: 1,764
How will the function know what the name of the new variable is?
such as this:
Expand|Select|Wrap|Line Numbers
  1. exampleFunction(string)
  2. {
  3. string = otherExample;
  4. }
  5.  
will that work for displaying the string that the user sends to the function?
I'm not sure that I understand your question.

Can you reform your question?

Savage
Jun 17 '07 #4

compman9902
100+
P: 105
I'm not sure that I understand your question.

Can you reform your question?

Savage
Sure.
When you make a function, a certain variable is usually declared for the variable that the program is passing to the function. Basically, How would the function in the include be able to read the variable passed to it by the program? Please give me code examples. Thank you.
Jun 17 '07 #5

Expert 10K+
P: 11,448
Sure.
When you make a function, a certain variable is usually declared for the variable that the program is passing to the function. Basically, How would the function in the include be able to read the variable passed to it by the program? Please give me code examples. Thank you.
You're overcomplicating matters; suppose I have two great functions, foo and bar:

Expand|Select|Wrap|Line Numbers
  1. int foo(double d) { /* great stuff goes on in here ... */ }
  2. int bar(long l) { /* even greater stuff goes on in here */ }
  3.  
I can build a header file foobar.h for those great functions like this:

Expand|Select|Wrap|Line Numbers
  1. #ifndef FOO_BAR
  2. #define FOO_BAR
  3. extern int foo(double);
  4. extern int bar(long);
  5. #endif
  6.  
and all I have to do is to include that header file in other source files:

Expand|Select|Wrap|Line Numbers
  1. #include "foobar.h"
  2.  
  3. int main() {
  4.    int r1= foo(3.1415);
  5.    int r2= bar(12345678L);
  6.    /* other stuff here ... */
  7.    return 0;
  8. }
  9.  
When it comes to linking, the functions foo and bar should be available of course,
maybe in a library or as a compiled translation unit of their own. The compiler
just assumes function foo and bar exist somewhere because I declared them so
in my include file foobar.h. Note the little tag at the top of the include file that
protects the content of the file to be included more than once.

kind regards,

Jos
Jun 17 '07 #6

compman9902
100+
P: 105
You're overcomplicating matters; suppose I have two great functions, foo and bar:

Expand|Select|Wrap|Line Numbers
  1. int foo(double d) { /* great stuff goes on in here ... */ }
  2. int bar(long l) { /* even greater stuff goes on in here */ }
  3.  
I can build a header file foobar.h for those great functions like this:

Expand|Select|Wrap|Line Numbers
  1. #ifndef FOO_BAR
  2. #define FOO_BAR
  3. extern int foo(double);
  4. extern int bar(long);
  5. #endif
  6.  
and all I have to do is to include that header file in other source files:

Expand|Select|Wrap|Line Numbers
  1. #include "foobar.h"
  2.  
  3. int main() {
  4.    int r1= foo(3.1415);
  5.    int r2= bar(12345678L);
  6.    /* other stuff here ... */
  7.    return 0;
  8. }
  9.  
When it comes to linking, the functions foo and bar should be available of course,
maybe in a library or as a compiled translation unit of their own. The compiler
just assumes function foo and bar exist somewhere because I declared them so
in my include file foobar.h. Note the little tag at the top of the include file that
protects the content of the file to be included more than once.

kind regards,

Jos
thanks, just finished it
Jun 17 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.