how can I make a hello world executable as big as possible?

Discussion in 'C Programming' started by K4 Monk, Mar 1, 2011.

  1. K4 Monk

    K4 Monk Guest

    I'm curious, how can I, either on windows or linux, compile a program
    so that all it does is "hello world" but is heavily bloated? Is there
    a way to statically link as many libraries as possible without using
    them? I'm inspired by the fake interview in which Bjarne Stroustrup
    claimed that g++ gives a 0.5 MB executable for hello world:
    http://www.nsbasic.com/ce/info/interview.shtml
    K4 Monk, Mar 1, 2011
    #1
    1. Advertising

  2. Kenneth Brody <> writes:
    [...]
    > That said, I did see a version of "Hello, world" that took command line
    > arguments, including things like "--help" and "--version", as well as
    > handled localization. A quick search doesn't find it, however.


    You're probably thinking of GNU hello, available at
    <ftp://ftp.gnu.org/gnu/hello/>.

    It's designed to be a canonical example of a GNU package.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Mar 4, 2011
    #2
    1. Advertising

  3. On Sat, 5 Mar 2011 11:48:55 -0800, kevin <> wrote:

    > This technique will make the program as arbitrarily large as your
    > system can stand:
    >
    > #include <stdio.h>
    > int main( void )
    > {
    > static char message[0x100000] = { "Hello, World!" };
    > puts( message );
    > return 0;
    > }
    >

    Probably. Many popular systems have IDATA regions which occupy as much
    space in the (object and) executable as their runtime size, and BSS
    regions which occupy no space in the executable (only runtime).
    The names may be different, but the concepts are widespread.

    But one system I worked on had a single data region in the executable,
    and compressed out all-zero pages (of 2048 bytes). Your example would
    only store one page, no matter how big you declare the array (up to a
    limit, which IIRC was 27 bits = 128M minus overhead). You'd need
    something like C99's
    static char message[0x1000000] = { 'a',
    [0x800] = 'b', [0x1000] = 'c', [0x1800] = 'd', etc etc }
    (and when I used this system it was before 1999).

    OTOH, it had a complicated symbol-info format, and #include'ing a
    bunch of headers whose contents you didn't actually use would give a
    huge executable without increasing runtime memory. <G>
    David Thompson, Mar 10, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vijay
    Replies:
    8
    Views:
    686
  2. Roy
    Replies:
    6
    Views:
    575
    Roedy Green
    Jan 7, 2008
  3. Shaguf
    Replies:
    0
    Views:
    323
    Shaguf
    Dec 24, 2008
  4. Ralph Spitzner
    Replies:
    2
    Views:
    256
    K4 Monk
    Mar 2, 2011
  5. Larry
    Replies:
    27
    Views:
    407
    Michele Dondi
    Jan 25, 2005
Loading...

Share This Page