Re: [Mingw-w64-public] C++ cout executable size

2017-06-04 Thread David Grayson
I was able to reproduce your problem.  The issue is that you declared
a variable named stdout, which is a name used by the C standard.  Just
rename that variable.

--David

On Sun, Jun 4, 2017 at 8:31 AM, bob by  wrote:
> 2017-06-02 15:47 GMT+04:00 bob by 
>
>> Can somebody here write a replacement for the standard cout, that will be
>> able to print strings and integers, and internally will just redirect to
>> puts and itoa? I'm only starting with C++, I'm not sure how to do it.
>>
>
> So, I'm trying to do this, This code seems to more or less work, but adding
> #include  causes compile error at the HANDLE. Error says
> "declaration of _imp__iob as array of references".
>
> I kind of want to try out std::string, even though I don't know how it's
> different from char*.
>
> #include 
>
> class cout_c
> {
> public:
> HANDLE stdout;
> void init()
> {
> stdout = GetStdHandle(STD_OUTPUT_HANDLE);
> }
> cout_c& operator<<(char* s)
> {
> WriteFile(stdout, s, strlen(s), NULL, NULL);
> return *this;
> }
> };
>
> cout_c cout;
>
> int main()
> {
> cout.init();
> cout << "1234567890";
> }
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-04 Thread bob by
2017-06-02 15:47 GMT+04:00 bob by 

> Can somebody here write a replacement for the standard cout, that will be
> able to print strings and integers, and internally will just redirect to
> puts and itoa? I'm only starting with C++, I'm not sure how to do it.
>

So, I'm trying to do this, This code seems to more or less work, but adding
#include  causes compile error at the HANDLE. Error says
"declaration of _imp__iob as array of references".

I kind of want to try out std::string, even though I don't know how it's
different from char*.

#include 

class cout_c
{
public:
HANDLE stdout;
void init()
{
stdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
cout_c& operator<<(char* s)
{
WriteFile(stdout, s, strlen(s), NULL, NULL);
return *this;
}
};

cout_c cout;

int main()
{
cout.init();
cout << "1234567890";
}
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-03 Thread LRN
On 6/3/2017 12:22 PM, bob by wrote:
> 
> Can you please tell how large C programs usually organize memory? Bunch of
> structures and globals I guess?

Yes. C is not Rust, it doesn't have an intricate memory ownership model. You
have chunks of memory and pointers to it. What you put there is up to you, but
- yes, structures and arrays tend to dominate. Global variables are not
encouraged, for obvious reasons. There are some tricks, like slice allocators
(which allow faster-than-malloc allocations of small uniformly-sized chunks of
memory), but that's for special cases. Generally it's just heap and stack.

You'd have to be more specific to get a more precise answer.

> 
> Any programs whose source you'd recommend reading?

I would recommend reading books. Much easier to find pertinent information
there. Read the source code to learn what it does or how it does it, and to
make modifications. If you must read the source code, read the projects that
generate documentation from it - that usually forces people to be more
descriptive and add more comments. Also, if a project has some kind of style
guide and best practices list, that's a plus - the code will be easier to read,
and the list itself might point you at interesting stuff.
I can probably suggest you look at GSoC projects, as they had to accommodate
newcomers, and thus they should have some pertinent info laying around on their
websites and wikis.

> 
> Not sure if I should send questions like that in this mailing list, maybe I
> should ask directly.

Well, MinGW-w64-related questions would be more appropriate here. On the other
hand, people here *do* have some answers, so you might as well keep going,
unless someone points you towards the door.

-- 
O< ascii ribbon - stop html email! - www.asciiribbon.org


signature.asc
Description: OpenPGP digital signature
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-03 Thread bob by
2017-06-02 17:30 GMT+04:00 LRN :

> On 6/2/2017 3:53 PM, bob by wrote:
> > On 2017-06-02 16:23 GMT+04:00 LRN wrote:
> >> On 6/2/2017 2:47 PM, bob by wrote:
> >>> Can somebody here write a replacement for the standard cout, that will
> be
> >>> able to print strings and integers, and internally will just redirect
> to
> >>> puts and itoa? I'm only starting with C++, I'm not sure how to do it.
> >>
> >> I feel compelled to cite my own first experience with C++.
> Specifically, i
> >> would like to mention that at the time i did not understand the
> difference
> >> between C and C++. It took me a while to understand the difference and
> >> realize
> >> that the programs i was writing were really just C programs, even
> though i
> >> was
> >> compiling them with a C++ compiler. I stopped writing in C++ shortly
> >> afterwards.
> >>
> >> I remembered that because you've mentioned cout and printf in the same
> >> sentence.
> >>
> >
> > Do you use datatypes like linked lists or trees or hashmaps? Can you
> share
> > some libraries or code to work with them?
> >
> > I'm trying to learn C++ just because a lot of code I see is written in
> C++.
> > Pretty much just in case.
>
> glib[1] is the easiest for me to name. In my experience, large-ish C
> projects
> tend to include their own (developed in-house or just copy-pasted from
> somewhere) implementations of linked lists or trees when needed. Or use
> other
> utility libraries (google for "C utility library") that complement the C
> standard library, which is rather bare by itself.
>
> If you want, you can google for "C vs C++". Also - look for articles on
> pros
> and cons of object-oriented programming in general, and C++ (as an OOP
> language) in particular. That might help you understand the current
> situation
> around C++ better.
>
> [1] https://en.wikipedia.org/wiki/GLib
>

Can you please tell how large C programs usually organize memory? Bunch of
structures and globals I guess?

Any programs whose source you'd recommend reading?

Not sure if I should send questions like that in this mailing list, maybe I
should ask directly.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-03 Thread bob by
2017-06-03 12:11 GMT+04:00 Mateusz Mikuła :

> Here is ios_base::Init https://github.com/gcc-mirror/
> gcc/blob/master/libstdc%2B%2B-v3/include/std/iostream#L74
> If you really want to understand what compiler put into your executable
> you have to disassemble it.
> Bear in mind that even if you knew whole source code of libstdc++ you
> would get different code in binary due to compiler optimizations and
> disabling them for final product is stupid unless they break something.
>

Now I'm curious where the __ioinit is...

Found this by accident, it seems related:
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/libstdc++/manual/manual/io.html

As I understood from that link, ideally you have only one #include
 per object file, overwise you'll end up with extra copies of
__ioinit in each. Don't quite understand that either, can't linker just
throw those away?


2017-06-03 12:37 GMT+04:00 Mateusz Mikuła :

> Pasted wrong link, here is fixed https://github.com/gcc-mirror/
> gcc/blob/master/libstdc%2B%2B-v3/include/bits/ios_base.h#L601


Don't see any real code still, there should be something like stdout =
GetStdHandle(STD_OUTPUT_HANDLE); somewhere.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-03 Thread Mateusz Mikuła
Pasted wrong link, here is fixed 
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/ios_base.h#L601

On June 3, 2017 10:11:30 AM GMT+02:00, "Mateusz Mikuła"  
wrote:
>Here is ios_base::Init
>https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/iostream#L74
>If you really want to understand what compiler put into your executable
>you have to disassemble it.
>Bear in mind that even if you knew whole source code of libstdc++ you
>would get different code in binary due to compiler optimizations and
>disabling them for final product is stupid unless they break something.
>
>On June 3, 2017 8:35:43 AM GMT+02:00, bob by 
>wrote:
>>2017-06-03 5:26 GMT+04:00 Liu Hao :
>>
>>> On 2017/6/3 0:18, bob by wrote:
>>>
 Can't find the code of std::ios_base::Init

 It should be somewhere in here, but I can't find it:
 https://gcc.gnu.org/onlinedocs/gcc-6.3.0/libstdc++/api/a00801.html

 Why do you want to find its source? It is merely the answer to your
>>> previous question: `#include ` will make your executable
>>larger,
>>> although you seem not using anything in that header,. And jon_y is
>>right
>>> for the reason.
>>
>>
>>I want to understand what runtime is doing. I don't want the code I
>>can't
>>understand to be in my exe, it makes me feel like I don't understand
>>the
>>program I myself wrote.
>>--
>>Check out the vibrant tech community on one of the world's most
>>engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>___
>>Mingw-w64-public mailing list
>>Mingw-w64-public@lists.sourceforge.net
>>https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-03 Thread Mateusz Mikuła
Here is ios_base::Init 
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/iostream#L74
If you really want to understand what compiler put into your executable you 
have to disassemble it.
Bear in mind that even if you knew whole source code of libstdc++ you would get 
different code in binary due to compiler optimizations and disabling them for 
final product is stupid unless they break something.

On June 3, 2017 8:35:43 AM GMT+02:00, bob by  wrote:
>2017-06-03 5:26 GMT+04:00 Liu Hao :
>
>> On 2017/6/3 0:18, bob by wrote:
>>
>>> Can't find the code of std::ios_base::Init
>>>
>>> It should be somewhere in here, but I can't find it:
>>> https://gcc.gnu.org/onlinedocs/gcc-6.3.0/libstdc++/api/a00801.html
>>>
>>> Why do you want to find its source? It is merely the answer to your
>> previous question: `#include ` will make your executable
>larger,
>> although you seem not using anything in that header,. And jon_y is
>right
>> for the reason.
>
>
>I want to understand what runtime is doing. I don't want the code I
>can't
>understand to be in my exe, it makes me feel like I don't understand
>the
>program I myself wrote.
>--
>Check out the vibrant tech community on one of the world's most
>engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>___
>Mingw-w64-public mailing list
>Mingw-w64-public@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-03 Thread bob by
2017-06-03 5:26 GMT+04:00 Liu Hao :

> On 2017/6/3 0:18, bob by wrote:
>
>> Can't find the code of std::ios_base::Init
>>
>> It should be somewhere in here, but I can't find it:
>> https://gcc.gnu.org/onlinedocs/gcc-6.3.0/libstdc++/api/a00801.html
>>
>> Why do you want to find its source? It is merely the answer to your
> previous question: `#include ` will make your executable larger,
> although you seem not using anything in that header,. And jon_y is right
> for the reason.


I want to understand what runtime is doing. I don't want the code I can't
understand to be in my exe, it makes me feel like I don't understand the
program I myself wrote.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread Liu Hao

On 2017/6/3 0:18, bob by wrote:

Can't find the code of std::ios_base::Init

It should be somewhere in here, but I can't find it: 
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/libstdc++/api/a00801.html


Why do you want to find its source? It is merely the answer to your 
previous question: `#include ` will make your executable 
larger, although you seem not using anything in that header,. And jon_y 
is right for the reason.


--
Best regards,
LH_Mouse


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread Ruben Van Boxem
Op 2 jun. 2017 9:54 p.m. schreef "bob by" :

2017-06-02 22:24 GMT+04:00 Ruben Van Boxem :

> Be sure to check the final program code size in case of using such a
> utility library vs just the C++ standard library. You might be
surprised...
>
> Also important to note c++ isn't just an object oriented language. It is
so
> much more. If you get through the initial syntactical and semantical
> hurdles of the language and its intricacies.
>
> Lastly I would like to emphasise that unless you are programming a
> microwave or router that this whole discussion based on the size of a
hello
> world program is outright ridiculous. Write a complex program, and then
> discuss the advantages of one language over another.
>
> And now, on to the weekend!
>

Rude. You told pretty much nothing.


I'm sorry you feel that way.

Let me sum up the things I told you and the list:
0. Tl;DR If you want to write c++ code, write c++ code and stop obsessing
over unimportant things like 500kB of binary.
Now for the points I did make in my previous message:
1. Executable size in the order of 500kB means nothing unless you are
programming a memory constrained system. Such a system won't be running
Windows, so getting your Hello World program size down is a waste of time.
2. Rewriting the logic contained in the C++ standard library, libgcc, etc
will require code. It will be less than but near the same size. Using a C
utility library to give you certain things will have a similar effect than
just using the C++ standard library.
3. I pointed out that a limiting definition of C++ as "object-oriented
language" is just not fair to the possibilities it provides. There is so
much more that C cannot possibly give you. Granted, I'm not saying one is
better than the other. Both have their domain. But C++ is a must paradigm
language in which you can write the most funky/cool stuff if you get the
hang of it.
Additionally, because you've got me typing again:
4. Don't reinvent the wheel. Especially when you're learning as you seem to
be. Writing your own cout will only result in bugs because you missed all
the corner cases. Especially when your code becomes more and more complex.

If you want the smallest executable possible, you don't link with any
runtime library (not even msvcrt), but instead link directly to ntdll.dll
and user32.dll, set up a custom entry point, and call the Win32 API
WriteConsole function. Just remember you can't actually do anything useful
then, because all of the C and C++ library functions are off limits.

Ruben


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread bob by
2017-06-02 22:24 GMT+04:00 Ruben Van Boxem :

> Be sure to check the final program code size in case of using such a
> utility library vs just the C++ standard library. You might be surprised...
>
> Also important to note c++ isn't just an object oriented language. It is so
> much more. If you get through the initial syntactical and semantical
> hurdles of the language and its intricacies.
>
> Lastly I would like to emphasise that unless you are programming a
> microwave or router that this whole discussion based on the size of a hello
> world program is outright ridiculous. Write a complex program, and then
> discuss the advantages of one language over another.
>
> And now, on to the weekend!
>

Rude. You told pretty much nothing.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread Ruben Van Boxem
Op 2 jun. 2017 3:32 p.m. schreef "LRN" :

On 6/2/2017 3:53 PM, bob by wrote:
> On 2017-06-02 16:23 GMT+04:00 LRN wrote:
>> On 6/2/2017 2:47 PM, bob by wrote:
>>> Can somebody here write a replacement for the standard cout, that will
be
>>> able to print strings and integers, and internally will just redirect to
>>> puts and itoa? I'm only starting with C++, I'm not sure how to do it.
>>
>> I feel compelled to cite my own first experience with C++. Specifically,
i
>> would like to mention that at the time i did not understand the
difference
>> between C and C++. It took me a while to understand the difference and
>> realize
>> that the programs i was writing were really just C programs, even though
i
>> was
>> compiling them with a C++ compiler. I stopped writing in C++ shortly
>> afterwards.
>>
>> I remembered that because you've mentioned cout and printf in the same
>> sentence.
>>
>
> Do you use datatypes like linked lists or trees or hashmaps? Can you share
> some libraries or code to work with them?
>
> I'm trying to learn C++ just because a lot of code I see is written in
C++.
> Pretty much just in case.

glib[1] is the easiest for me to name. In my experience, large-ish C
projects
tend to include their own (developed in-house or just copy-pasted from
somewhere) implementations of linked lists or trees when needed. Or use
other
utility libraries (google for "C utility library") that complement the C
standard library, which is rather bare by itself.

If you want, you can google for "C vs C++". Also - look for articles on pros
and cons of object-oriented programming in general, and C++ (as an OOP
language) in particular. That might help you understand the current
situation
around C++ better.


Be sure to check the final program code size in case of using such a
utility library vs just the C++ standard library. You might be surprised...

Also important to note c++ isn't just an object oriented language. It is so
much more. If you get through the initial syntactical and semantical
hurdles of the language and its intricacies.

Lastly I would like to emphasise that unless you are programming a
microwave or router that this whole discussion based on the size of a hello
world program is outright ridiculous. Write a complex program, and then
discuss the advantages of one language over another.

And now, on to the weekend!


[1] https://en.wikipedia.org/wiki/GLib


--
O< ascii ribbon - stop html email! - www.asciiribbon.org


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread Liu Hao

On 2017/6/2 20:21, bob by wrote:

2017-06-02 16:05 GMT+04:00 JonY :


On 06/02/2017 11:47 AM, bob by wrote:

Wonder why including  bloats my exe file so much (extra 900

KiB,

with statically linked libraries), even if nothing from there is used.

Why

cout requires so much code.



It includes static initializer code to initialize all the std::*
members, so you are increasing code size by merely including the header.



Can I get more info, what exactly it does and why I need it?


http://en.cppreference.com/w/cpp/io/ios_base/Init

(AFAIK this is the only identifier required by the C++ standard that 
begins with an uppercase letter, without any leading underscores of course.)


--
Best regards,
LH_Mouse


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread LRN
On 6/2/2017 3:53 PM, bob by wrote:
> On 2017-06-02 16:23 GMT+04:00 LRN wrote:
>> On 6/2/2017 2:47 PM, bob by wrote:
>>> Can somebody here write a replacement for the standard cout, that will be
>>> able to print strings and integers, and internally will just redirect to
>>> puts and itoa? I'm only starting with C++, I'm not sure how to do it.
>>
>> I feel compelled to cite my own first experience with C++. Specifically, i
>> would like to mention that at the time i did not understand the difference
>> between C and C++. It took me a while to understand the difference and
>> realize
>> that the programs i was writing were really just C programs, even though i
>> was
>> compiling them with a C++ compiler. I stopped writing in C++ shortly
>> afterwards.
>>
>> I remembered that because you've mentioned cout and printf in the same
>> sentence.
>>
> 
> Do you use datatypes like linked lists or trees or hashmaps? Can you share
> some libraries or code to work with them?
> 
> I'm trying to learn C++ just because a lot of code I see is written in C++.
> Pretty much just in case.

glib[1] is the easiest for me to name. In my experience, large-ish C projects
tend to include their own (developed in-house or just copy-pasted from
somewhere) implementations of linked lists or trees when needed. Or use other
utility libraries (google for "C utility library") that complement the C
standard library, which is rather bare by itself.

If you want, you can google for "C vs C++". Also - look for articles on pros
and cons of object-oriented programming in general, and C++ (as an OOP
language) in particular. That might help you understand the current situation
around C++ better.

[1] https://en.wikipedia.org/wiki/GLib


-- 
O< ascii ribbon - stop html email! - www.asciiribbon.org


signature.asc
Description: OpenPGP digital signature
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread JonY
On 06/02/2017 12:53 PM, bob by wrote:
> 2017-06-02 16:23 GMT+04:00 LRN :
> 
>> On 6/2/2017 2:47 PM, bob by wrote:
>>> Can somebody here write a replacement for the standard cout, that will be
>>> able to print strings and integers, and internally will just redirect to
>>> puts and itoa? I'm only starting with C++, I'm not sure how to do it.
>>
>> I feel compelled to cite my own first experience with C++. Specifically, i
>> would like to mention that at the time i did not understand the difference
>> between C and C++. It took me a while to understand the difference and
>> realize
>> that the programs i was writing were really just C programs, even though i
>> was
>> compiling them with a C++ compiler. I stopped writing in C++ shortly
>> afterwards.
>>
>> I remembered that because you've mentioned cout and printf in the same
>> sentence.
>>
> 
> Do you use datatypes like linked lists or trees or hashmaps? Can you share
> some libraries or code to work with them?
> 
> I'm trying to learn C++ just because a lot of code I see is written in C++.
> Pretty much just in case.

You can take a look at the Linux Kernel and find out how they do it in
pure C :)

Nothing is stopping you from using printf in C++ anyway.



signature.asc
Description: OpenPGP digital signature
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread LRN
On 6/2/2017 2:47 PM, bob by wrote:
> Can somebody here write a replacement for the standard cout, that will be
> able to print strings and integers, and internally will just redirect to
> puts and itoa? I'm only starting with C++, I'm not sure how to do it.

I feel compelled to cite my own first experience with C++. Specifically, i
would like to mention that at the time i did not understand the difference
between C and C++. It took me a while to understand the difference and realize
that the programs i was writing were really just C programs, even though i was
compiling them with a C++ compiler. I stopped writing in C++ shortly afterwards.

I remembered that because you've mentioned cout and printf in the same sentence.

-- 
O< ascii ribbon - stop html email! - www.asciiribbon.org


signature.asc
Description: OpenPGP digital signature
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread bob by
2017-06-02 16:05 GMT+04:00 JonY :

> On 06/02/2017 11:47 AM, bob by wrote:
> > Wonder why including  bloats my exe file so much (extra 900
> KiB,
> > with statically linked libraries), even if nothing from there is used.
> Why
> > cout requires so much code.
> >
>
> It includes static initializer code to initialize all the std::*
> members, so you are increasing code size by merely including the header.
>

Can I get more info, what exactly it does and why I need it?


>
> > I downloaded gcc-6.3.0 source code, and found libstdc++-v3\src\c++11
> > folder. I guess the "cout <<" is somewhere in here, but I'm not sure
> where
> > to look. Here is the full function name that my debugger is looking for:
> >
> > std::basic_ostream& std::operator<<
> > (std::basic_ostream >> &, char const*)
> >
> > Can somebody here write a replacement for the standard cout, that will be
> > able to print strings and integers, and internally will just redirect to
> > puts and itoa? I'm only starting with C++, I'm not sure how to do it.
>
> I suppose you want to just use printf.
>

Aint cout is more safe? I will never write a wrong % code, and it's just
more compact. Plus it will allow for compile time checks, instead of
runtime only like with printf.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread JonY
On 06/02/2017 11:47 AM, bob by wrote:
> Wonder why including  bloats my exe file so much (extra 900 KiB,
> with statically linked libraries), even if nothing from there is used. Why
> cout requires so much code.
> 

It includes static initializer code to initialize all the std::*
members, so you are increasing code size by merely including the header.

> I downloaded gcc-6.3.0 source code, and found libstdc++-v3\src\c++11
> folder. I guess the "cout <<" is somewhere in here, but I'm not sure where
> to look. Here is the full function name that my debugger is looking for:
> 
> std::basic_ostream& std::operator<<
> (std::basic_ostream> &, char const*)
> 
> Can somebody here write a replacement for the standard cout, that will be
> able to print strings and integers, and internally will just redirect to
> puts and itoa? I'm only starting with C++, I'm not sure how to do it.

I suppose you want to just use printf.




signature.asc
Description: OpenPGP digital signature
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-02 Thread bob by
Wonder why including  bloats my exe file so much (extra 900 KiB,
with statically linked libraries), even if nothing from there is used. Why
cout requires so much code.

I downloaded gcc-6.3.0 source code, and found libstdc++-v3\src\c++11
folder. I guess the "cout <<" is somewhere in here, but I'm not sure where
to look. Here is the full function name that my debugger is looking for:

std::basic_ostream& std::operator<<
(std::basic_ostream&, char const*)

Can somebody here write a replacement for the standard cout, that will be
able to print strings and integers, and internally will just redirect to
puts and itoa? I'm only starting with C++, I'm not sure how to do it.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-01 Thread David Grayson
On Thu, Jun 1, 2017 at 11:49 AM, bob by  wrote:
> I linked all libraries statically, before that it depended on
> libgcc_s_dw2-1.dll and libwinpthread-1.dll, and probably something
> else too. It was around 500 KiB originally, now it is almost 1000 KiB.

if your program depends on those DLLs, it means that the libaries
provided by those DLLs were not linked in statically.  A DLL is a
dynamic shared object that gets loaded at runtime, while a static
library is something that gets included into your EXE at link time and
makes your EXE bigger.

> Here is the output of my g++ -v

OK, so you are using GCC 6.3.0, provided by the MSYS2 project.  You
can see how that version of GCC was built and track down its source
code by looking at the build script here:

https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-gcc

> Is it possible to make something that will look like cout << "some
> string", but will just redirect to printf internally and be more
> lightweight? I'm very new to C++ to mess with runtime by myself.

Sure, you can define your own simple class that overrides the left
shift operator and does arbitrary stuff with the arguments.  C++
method overloading would allow you to define different overloads of
the operator that handle the printing of different data types.  I
don't think saving a megabyte of executable size is enough to justify
that effort, especially when you could save that size by using printf.
Also, by making your own cout, you make it harder for other C++
programmers to understand and modify your code.

--David

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-01 Thread bob by
> How huge is "weirdly huge"? Does your executable depend on any MinGWDLLs,
like libstdc++-6.dll?

I linked all libraries statically, before that it depended on
libgcc_s_dw2-1.dll and libwinpthread-1.dll, and probably something
else too. It was around 500 KiB originally, now it is almost 1000 KiB.

> The code in the "std" namespace is generally provided by libstdc++v3,
which is a component of GCC and can be found in the GCC
source:ftp://ftp.gnu.org/gnu/gcc/  You haven't said what version of
GCC you
are using or what distribution of mingw-w64, so it's hard to point you
to the exact source.

Here is the output of my g++ -v

$ g++ -v
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw32\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.3.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../gcc-6.3.0/configure --prefix=/mingw32
--with-local-prefix=/mingw32/local --build=i686-w64-mingw32
--host=i686-w64-mingw32 --target=i686-w64-mingw32
--with-native-system-header-dir=/mingw32/i686-w64-mingw32/include
--libexecdir=/mingw32/lib --enable-bootstrap --with-arch=i686
--with-tune=generic
--enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared
--enable-static --enable-libatomic --enable-threads=posix
--enable-graphite --enable-fully-dynamic-string
--enable-libstdcxx-time=yes --disable-libstdcxx-pch
--disable-libstdcxx-debug --disable-isl-version-check --enable-lto
--enable-libgomp --disable-multilib --enable-checking=release
--disable-rpath --disable-win32-registry --disable-nls
--disable-werror --disable-symvers --with-libiconv --with-system-zlib
--with-gmp=/mingw32 --with-mpfr=/mingw32 --with-mpc=/mingw32
--with-isl=/mingw32 --with-pkgversion='Rev3, Built by MSYS2 project'
--with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as
--with-gnu-ld --disable-sjlj-exceptions --with-dwarf2
Thread model: posix
gcc version 6.3.0 (Rev3, Built by MSYS2 project)

>I'd recommend using printf, like those other people you talked to.
The code for that is provided by Microsoft in msvcrt.dll so it won't
be part of your executable.

Is it possible to make something that will look like cout << "some
string", but will just redirect to printf internally and be more
lightweight? I'm very new to C++ to mess with runtime by myself.

>Also, did you remember to run the binutils "strip" utility on your
executable before deciding it was huge?

Yes, there is "-s" in linking flags, should be the same thing.

Sorry if formatting or something else is wrong, second time using mailing lists.
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-01 Thread David Grayson
Also, did you remember to run the binutils "strip" utility on your
executable before deciding it was huge?

--David

On Thu, Jun 1, 2017 at 10:54 AM, David Grayson  wrote:
> How huge is "weirdly huge"?  Does your executable depend on any MinGW
> DLLs, like libstdc++-6.dll?
>
> The code in the "std" namespace is generally provided by libstdc++v3,
> which is a component of GCC and can be found in the GCC source:
> ftp://ftp.gnu.org/gnu/gcc/  You haven't said what version of GCC you
> are using or what distribution of mingw-w64, so it's hard to point you
> to the exact source.
>
> I'd recommend using printf, like those other people you talked to.
> The code for that is provided by Microsoft in msvcrt.dll so it won't
> be part of your executable.
>
> --David
>
> On Thu, Jun 1, 2017 at 9:41 AM, bob by  wrote:
>> Hello. Wrote my hello world in C++, but executable size is weirdly huge.
>>
>> Can I get a lightweight replacement for the cout << operator? People
>> recommend to just use printf instead, but maybe there is a way.
>>
>> By the way, where can I get source code of std? I'd like to see how it
>> works in debugger.
>> --
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> ___
>> Mingw-w64-public mailing list
>> Mingw-w64-public@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] C++ cout executable size

2017-06-01 Thread David Grayson
How huge is "weirdly huge"?  Does your executable depend on any MinGW
DLLs, like libstdc++-6.dll?

The code in the "std" namespace is generally provided by libstdc++v3,
which is a component of GCC and can be found in the GCC source:
ftp://ftp.gnu.org/gnu/gcc/  You haven't said what version of GCC you
are using or what distribution of mingw-w64, so it's hard to point you
to the exact source.

I'd recommend using printf, like those other people you talked to.
The code for that is provided by Microsoft in msvcrt.dll so it won't
be part of your executable.

--David

On Thu, Jun 1, 2017 at 9:41 AM, bob by  wrote:
> Hello. Wrote my hello world in C++, but executable size is weirdly huge.
>
> Can I get a lightweight replacement for the cout << operator? People
> recommend to just use printf instead, but maybe there is a way.
>
> By the way, where can I get source code of std? I'd like to see how it
> works in debugger.
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public