Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Some general questions about C++ and .lib's (how to make...)

Posted on 2004-10-22
6
Medium Priority
?
205 Views
Last Modified: 2010-04-01
Hi, I have some little general questions.
1)
When you have a block of code which consist mainly of two parts:
->1)initialisation and conversion of input
->2)calculation of a number, which makes use of the initialised and conevrted data
And you have to do the second part 1000's of times;
What is then the fastest way to do that (since it's difficult to make a function with 20 arguments or so...).
I know that you can put it just in a loop, but that's not what I want (I want it to be outside the code).
2)
Can you easily make a lib with two functions (void Init() and Calculate(lots of parameters) from normal code (main()) ? If so, where can I find a tutorial? I searched but didn't find anything usable.

Thanks.
0
Comment
Question by:DEEGBAL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Expert Comment

by:rstaveley
ID: 12379249
You are probably looking at writing a class.

e.g.

class X {
        // here's the class data...
        // ...
public:
        Init(); // Initialises the class data
        Calculate(); // Runs calclations based on the class data
};
0
 
LVL 19

Assisted Solution

by:mrwad99
mrwad99 earned 100 total points
ID: 12379938
>> Can you easily make a lib with two functions (void Init() and Calculate(lots of parameters) from normal code (main()) ? If so, where can I find a tutorial? I searched but didn't find anything usable.

I think what you are after is a DLL.  Read http://www.flipcode.com/tutorials/tut_dll01.shtml for more info.  You will get the LIB when you compile the DLL.
0
 

Author Comment

by:DEEGBAL
ID: 12382267
and is this correct:
->a lib is for static linking
->a dll is for dynamic linking
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Accepted Solution

by:
rstaveley earned 400 total points
ID: 12382948
In the Windows world a .lib is used for static linkage and .dll is used for dynamic linkage.

Your options are as follows:

(1) Distribute your class implementation and header source code (.cpp and .h). Advantages, somebody can choose to compile with different compiler settings than those you chose.

(2) Distribute an object file compiled from your source code with the header (.obj and .h). Advantages (dubious), you keep your source code secret and save the fraction of a second required to recompile it.

(3) Distribute a library for static linkage and your header (.lib and .h). Advantages, you can distribute a whole load of .obj files in a .lib and it should be easy for you client to link the .obj files into his project.

(4) Distribute a dynamic linked library for dynamic linkage (.dll). Advantages, if lots of programs need to use this code at the same time, it saves some memory. Disadvantages - you need to learn some tricks to get up and running with this.

Before you get hung up on libraries, I recommend you make sure you can do (1), which requires the minimum knowledge. It sounds like you are relatively new to C++ and libraries are relatively advanced things to be playing with.

You need to make your code modular so that the required functionality can be moved into another project. You also ought to consider using object orientated design - i.e. wrap your data up into a class - to address the first part of your question. I recommend that you develop a harness module consisting of main(). The harness module includes the header file for your Init() and Calculate() code, which preferably is in a class. The Init() and Calculate() code should be in a separate module (i.e. separate .cpp file) so that you can test it with your harness and then move it to your required project(s) when it is debugged.
0
 

Author Comment

by:DEEGBAL
ID: 12389766
Thanks a lot.
That made a lot clear.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 12389778
>> Thanks a lot.

Glad to help.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question