flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Why C++ programs are so big?

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 14 Aug 2023, 13:17
Compile with -s switch can save the binary executable size by 1KB. But -Os actually increase the size, not decrease it.


Description: Compile with -s switch
Filesize: 47.53 KB
Viewed: 1631 Time(s)

s.png


Post 14 Aug 2023, 13:17
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 14 Aug 2023, 15:11
You compiled c++ code as release ?
Or debug ?

Maybe in exe c++ put some extra code, like security or some libs.

Minimal visual studio c++ dll 10 kb

On fasm 1kb dll
Post 14 Aug 2023, 15:11
View user's profile Send private message Reply with quote
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 14 Aug 2023, 15:23
Roman wrote:
You compiled c++ code as release ?
Or debug ?

Maybe in exe c++ put some extra code, like security or some libs.

Minimal visual studio c++ dll 10 kb

On fasm 1kb dll


Thanks for your reply, Roman.

This is C, C doesn't have Release or Debug build. Question

Last time I tried compile C++ "Hello, world" console app, and get 10,752 bytes, so you're right, it is about 10KB.

FASM can be small, you're right again, 1024 bytes.
Post 14 Aug 2023, 15:23
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3914
Location: vpcmipstrm
bitRAKE 14 Aug 2023, 19:05
Flier-Mate wrote:
Compile with -s switch can save the binary executable size by 1KB. But -Os actually increase the size, not decrease it.
The -Oz option continues to improve on compilers - producing smaller code - if you're okay with a little extra build times.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 14 Aug 2023, 19:05
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1586
Location: Toronto, Canada
AsmGuru62 14 Aug 2023, 22:31
Quote:

C doesn't have Release or Debug build.

Weird. Visual Studio, which I have, has both of these options when I am building my "C" project.
And if I look at disassembled codes -- they are different.
Post 14 Aug 2023, 22:31
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20067
Location: In your JS exploiting you and your system
revolution 14 Aug 2023, 23:13
gcc also has debug and release options.

The inclusion of debug symbols is the most obvious difference with regard to size of the output.
Post 14 Aug 2023, 23:13
View user's profile Send private message Visit poster's website Reply with quote
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 15 Aug 2023, 10:15
bitRAKE wrote:
Flier-Mate wrote:
Compile with -s switch can save the binary executable size by 1KB. But -Os actually increase the size, not decrease it.
The -Oz option continues to improve on compilers - producing smaller code - if you're okay with a little extra build times.


Maybe my compiler on disk is outdated, I got this error when trying to use -Oz:
Code:
boo@DESKTOP-1V5DHQJ:/mnt/c/Users/BOO/Projects$ gcc h.c -Oz -o h
cc1: error: argument to ‘-O’ should be a non-negative integer, ‘g’, ‘s’ or ‘fast’    
Post 15 Aug 2023, 10:15
View user's profile Send private message Reply with quote
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 15 Aug 2023, 10:16
AsmGuru62 wrote:
Quote:

C doesn't have Release or Debug build.

Weird. Visual Studio, which I have, has both of these options when I am building my "C" project.
And if I look at disassembled codes -- they are different.


I didn't know VS can be used to compile C projects as well.... Embarassed
Post 15 Aug 2023, 10:16
View user's profile Send private message Reply with quote
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 15 Aug 2023, 10:16
revolution wrote:
gcc also has debug and release options.

The inclusion of debug symbols is the most obvious difference with regard to size of the output.


Thank you for the correction.
Post 15 Aug 2023, 10:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20067
Location: In your JS exploiting you and your system
revolution 15 Aug 2023, 10:22
Flier-Mate wrote:
I didn't know VS can be used to compile C projects as well.... Embarassed
I would imagine that is its main purpose for existence.
Post 15 Aug 2023, 10:22
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2418
Furs 15 Aug 2023, 12:35
Flier-Mate wrote:
Compile with -s switch can save the binary executable size by 1KB. But -Os actually increase the size, not decrease it.
Just pass -s to gcc to strip debug symbols, and don't use -g or any other debug option.

You can also strip them after-the-fact with strip -s command line tool.
Post 15 Aug 2023, 12:35
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1586
Location: Toronto, Canada
AsmGuru62 15 Aug 2023, 17:27
The size of debug symbols aside -- the Released version of code (assembly code) is smaller by some degree.
Register allocation and all that "dark art of optimization techniques".
Post 15 Aug 2023, 17:27
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.