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

Hi, I have some little general questions.
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).
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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You are probably looking at writing a class.


class X {
        // here's the class data...
        // ...
        Init(); // Initialises the class data
        Calculate(); // Runs calclations based on the class data
>> 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 for more info.  You will get the LIB when you compile the DLL.
DEEGBALAuthor Commented:
and is this correct:
->a lib is for static linking
->a dll is for dynamic linking
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DEEGBALAuthor Commented:
Thanks a lot.
That made a lot clear.
>> Thanks a lot.

Glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.