I am trying to get public struct to whole project which data should be accessed from everywhere like is possible in C, but have problems to do that.

It is possible to do exactly like it was possible in C. Code you have shown will not work in C.
I suppose you want global variable of type _ini. If ypu want an OO approach, you probably should look into Singletone pattern: it was created to make sure tht there could be only one global accessible variable.

Also I suggest to read more about variables, their visibility and storage duration. You clearly have problems with that.

But after returning from connectiondata I havent data in ini structure.

That's because the ini variable inside the function is local to that function - it doesn't affect any other variables elsewhere.

You could send a reference to a object of type _ini to the connectiondata function - then it's data will be changed.

beginplus2 wrote:

How to achieve that in general, if possible out of classes?

Sure you can do this with classes - have a read of the classes section of the tutorial on this site (top left of this page) . If you do this correctly - with a separate header file & .cpp file, you can include the header file into whichever .cpp file needs to use it.

If you have a class - then the connectiondata function could be a constructor & the DBconnect function a member of the class, the variables it uses should be private data members of the class.

Btw, did you intend for the DBconnect function to be recursive?

You also need a constructor & public functions which make up the interface for the class. Don't be tempted to have a get / set function for every member of the class - particularly set functions which are straight assignment are very bad news.

The problem is that object ini was defined twice. The first its definition is in the file where you defined function connectiondata because you included the header with the object definition in this file. The second its definition is in the file where there is main function because you again included the same header file.
Some linkers when they see two definitions of the same object with external linkage convert such an object as having internal linkage. As the result you get two objects of the same type and with the same name that are in fact different and are not visible outside compilation units where they are defined.
So function connectiondata changes the object that is in the compilation unit where there is the definition of the function. At the same time the other object with the same name that is in main was not changed.
To correct the situation you should write in the header

extern struct _ini ini;

and in the module with the function definition of connectiondata write

Vlad, sorry, this is my starting touch with C++, but I have some experience with C so I am included header as needed in both files.

I declared local structure in function by mistake and ununderstanding.
Now I am repair example by your advices and it is shown above, (I repair previous post).
It compiles OK but don't transfer data. What more can I do to get it working?

That from main I can use out of functions, at top of program and then ini is reachable allaround, just what I search for...

But when we takling...
If I use "namespace std" (like for strings), include C++ headers like <string> and assign one string like mystring = "mytry" then I get compiled exe about 430 kb (under release). Same program, if I use C strings is about 9.5 kb (exe).

> If I use "namespace std" (like for strings), include C++ headers like <string>
> and assign one string like mystring = "mytry"
> then I get compiled exe about 430 kb (under release).
> Same program, if I use C strings is about 9.5 kb (exe).
> Is this normal

It is normal for a C++ program to have a larger memory footprint. For instance, the standard C++ streams are instantiated in addition to the standard C streams, there are a few more allocators than malloc() and friends, the implementation of the C++ portion of the library may call C library functions anyway, and so on. How much more depends on the implementation.

What platform do you intend to run this code on? Where 430 kb would be deemed to be extravagant?

JLBorges,
I try this on windows and intend to try on linux also.
As unexperience in C++ I have to ask is this normal and common, nothing more.
What this brings in practice I will see later with advancing...

Then just ignore the difference in size - 400 kb is not something that one would give a second thought to on these platforms. Open Task Manager and check the memory usage of the programs that you regularly - the browser, IDE etc.

This program is tiny and 430 kb vs. 10 kb looks like a lot. For a somewhat bigger program, 5 MB vs. 5.5 MB wouldn't look all that different.

Defining of globals can be in public area (NOT inside any function) of any file which includes common.h, but not in more than only one file!! That way structure p is accesible on all files which includes common.h.