Slashdot Mirror


Simpler "Hello World" Demonstrated In C

An anonymous reader writes "Wondering where all that bloat comes from, causing even the classic 'Hello world' to weigh in at 11 KB? An MIT programmer decided to make a Linux C program so simple, she could explain every byte of the assembly. She found that gcc was including libc even when you don't ask for it. The blog shows how to compile a much simpler 'Hello world,' using no libraries at all. This takes me back to the days of programming bare-metal on DOS!"

117 of 582 comments (clear)

  1. BTDT by argent · · Score: 2, Insightful

    *sigh*

    Been there done that... on the PDP-11 in 1979.

    1. Re:BTDT by maxume · · Score: 2, Informative

      The muppetlabs link ends with the entire program overlapped into the ELF header, and part of the header left off.

      (It is just a toy program that returns 42 to the OS, but he gets it down to 45 bytes.)

      --
      Nerd rage is the funniest rage.
    2. Re:BTDT by tomhudson · · Score: 5, Insightful

      She found that gcc was including libc even when you don't ask for it.

      This is basic knowledge that ANYONE using c should know - that the startup library is linked to so it can find main.

      This is almost as lame as their previous slashvertisement/product_whoring - where they claimed to have gotten around the Mythical Man-Month and quadrupled output - and it turned out that neither claim was true.

      And their lame excuse, which I derided in this comment:

      Greg Price wrote:

      "what I hoped to get across in this post is that that's not true--in the right circumstances, adding people to a software project can get a lot done, even in a short time"

      As many people have pointed out, you did NOT add people to a software project. You created a dozen small, one-person projects. Your self-serving reply to all that is just one more mis-representation. Have you no shame?

      I'm sure we're not the only ones to have used embedded assembler in c programs.

    3. Re:BTDT by crossmr · · Score: 4, Informative

      What a shock this comes from Kdawson. I'm about one more kdawson article away from dumping slashdot. I can't imagine that all the people in the slashdot batcave aren't laughing at this tool.
      I sometimes wonder if he just goes out and gets completely hammered at lunch then comes back and picks a few articles.

    4. Re:BTDT by h4rr4r · · Score: 4, Interesting

      Some people like their code to run on OSes for grownups.

    5. Re:BTDT by guyminuslife · · Score: 5, Funny

      The fact that people would even still use C at all for anything anywhere ever shocks me.

      I started writing device drivers in Ruby, and have never looked back.

      In order to get Ruby to run on my system, I run it in an interpreter. The interpreter is written in Java, which is a much faster language and therefore more suitable as an interpreter.

      The JVM on my system is written in C#. I know that C# is comparable to Java in terms of efficiency, but since this is a Windows machine, I figure it's "closer to the metal."

      The implementation of the .NET framework on my computer (and the Windows operating system itself) is written in Ruby. Since I already have a Ruby interpreter on my system, this presents no problems.

      --
      I don't believe in time. It's a grand conspiracy designed to sell watches.
    6. Re:BTDT by guyminuslife · · Score: 2, Funny

      I remember those. We used to have to carry them around in the snow, uphill both ways. ;-)

      --
      I don't believe in time. It's a grand conspiracy designed to sell watches.
    7. Re:BTDT by palegray.net · · Score: 2, Informative

      It is just a toy program that returns 42 to the OS, but he gets it down to 45 bytes.

      Since computer science tends to be such a male dominated field, I think it's worth pointing out that the author is a woman.

    8. Re:BTDT by Anne+Thwacks · · Score: 3, Interesting
      Not permanently running processes, libraries do not exist as an independent process, but are used by other processes. Regardless of the number of processes executing the code, only a single copy is ever loaded in memory - the entry points are made available via a table, and if anyone loads a copy, everyone has access to that copy (obviously with their own memory for variables). This is easy, because code and data sit in separate memory spaces logically, even though they don't do so physically. (And the code pages have the execute bit set, data doesn't - yes 20 years before Windows had this feature!)

      "Single instance only" applied to all code - applications, libraries and OS. We often used to have 16 users on an 11/70 with 1MW of memory (ie 2MB) - all running the same program, so only one copy was resident. (or one of us was running the C or Fortran compilers :-)

      isn't that how the BSDs do it today?

      In RSX/11, programs could be "installed" so that they made their location on disk known to the OS, so when you ran a program, it was not necessary to search the file system for it. The location on disk, and offset to the entry point, was already known. A program could have multiple entry points (like grep, egrep etc), and libraries just used this mechanism. The dynamic linker stored the program (library) name and index into a table of entry points. I think early implementations statically linked the code to hack this stuff, before it became part of the OS.

      If the search of the program you asked for found nothing, then the directories were searched. It was laziness of the users that meant the default strategy was used for most applications. I think VMS continued to support the install option, but I cant remember. I don't think Un*x ever did.

      Programs only loaded the pages that were in use, and pages not in use were eventually swapped out. So huge programs did not take for ever to load - you loaded the first page, and jumped to it - then loaded which ever pages execution went to - so you did not need to spend years designing overlay strategies! This was possible because pages could load anywhere - the PDP11 supported "position independent code" (All modern 16 and 32 bit processors could still do this).

      Don't you young people know anything? I know this, and I didn't even do computer science in college!

      Get off my lawn.

      --
      Sent from my ASR33 using ASCII
    9. Re:BTDT by ta+bu+shi+da+yu · · Score: 2, Interesting

      You know that this is a repost of a 2002 slashdot article?

      --
      XML is like violence. If it doesn't solve the problem, use more.
    10. Re:BTDT by MichaelSmith · · Score: 3, Interesting

      I think VMS continued to support the install option, but I cant remember. I don't think Un*x ever did.

      IIRC install in VMS was to register a privileged library with the OS. A library like that could do stuff the calling process couldn't do. Most likely it was install image.obj/priv=sysprv,setprv and so on.

      My experience with RSX was with a traffic signal application called SCATS. I once interviewed for a job in a hospital where they supported ~60 users on a single machine, probably an 11/84.

      Our SCATS systems had up to 16 DZ11 MUX cards for 128 serial lines. I have never seen a system which could handle that many interrupts and run so cool in the sense that it was always responsive regardless of load and it would chug away for years without showing any signs of stress.

      BSD is as close as you would get to that with modern systems. Maybe QNX though I haven't worked with that OS.

    11. Re:BTDT by kevingolding2001 · · Score: 4, Insightful

      *sigh*

      Been there done that... on the PDP-11 in 1979.

      And did you write up a nice article for other people to learn from what you had done?

      I think the real value here is not that she did this, but that she wrote it up in a nice easy to read way so that you can follow her train of thought and get a feel for how one goes about tinkering with compilers and such.

      This adds value for people like me who are not as smart as you. I could never have done this on a PDP-11 (although I did have access to one back in my days at university). I also previously would not have know enough to do this in Linux. But having read this article I feel I have learnt something and have a new insight into how linkers and libraries work. Who knows, maybe I will be able to do something similar myself after this learning experience, and for that I am grateful to Jessica for doing it, writing about it and (I'm guessing it was her) submitting it to /.

      Now I shall respectfully step off your lawn.

    12. Re:BTDT by dzfoo · · Score: 4, Funny

      I have a suggestion: If you write your JVM in Visual Basic instead of C#, it'll be portable, since most old microcomputers included BASIC in ROM. And, of course, .NET already brings Visual Basic.NET!

            -dZ.

      --
      Carol vs. Ghost
      ...Can you save Christmas?
    13. Re:BTDT by argent · · Score: 3, Interesting

      Was that in RSX11-M?

      Version 6 UNIX. I didn't abuse a.out as badly as this example abuses elf, though.

      Really, with a.out, it wasn't abuse. That format LIKED these kinds of games. When I was hacking in Forth I wrote a "snapshot" word that did something like

      : snapshot fork dup 0= if drop abort then waitpid -1 = if 0 else " mv core snap.out; patch-to-executable snap.out" system 1 then ;

      Where patch-to-executable took advantage of the fact that an a.out was basically a core dump with some extra segments... and you could leave those segments off if you needed to. :)

      I did some nasty stuff on RSX-11, though. Portable file and terminal I/O was a pain in the butt, because text files were variant record files with each line having a count and a length and a record/line type field and IIRC occasional block alignment issues, so to read and write text files in Forth I had a FORTRAN main that called Forth through an assembly glue routine, then called back to FORTRAN for textfile I/O. Also got tired of FORTRAN formatted I/O so I wrote a version of sprintf for my RATFOR code that used assembly glue to implement varargs in FORTRAN. Ah, the good old days...

    14. Re:BTDT by RMS+Eats+Toejam · · Score: 3, Insightful

      A better solution for everyone is to replace Kdawson with an editor who doesn't have shit for brains. This would give us more quality articles and less garbage without having to modify any settings at all.

      --
      Turning to a Linux advocate for thoughts on Microsoft is like asking Hitler how he felt about the Jews.
    15. Re:BTDT by argent · · Score: 2, Informative

      I don't think Un*x ever did.

      UNIX used the sticky bit instead. UNIX also supported Split I&D on the 11/70 before M+ came out with Split I&D support on RSX.

      I don't think you're remembering right about overlays on RSX. I know I spent WAY too much time waiting for TKB on RSX because it was sitting there trying to cram stuff into overlays. Also, while later PDP-11s technically could support demand paging the 8k page size in a max of 64k addressible memory made it a marginal technique, and I'm pretty sure it was never used, even by M+.

      UNIX supported shared code, too. We had over 35 users at a time on the Cory Hall 11/70 at Berkeley. It was OK under Version 6, but got painfully slow during finals week after they upgraded to Version 7. The Math/Stat department had an 11/60 and could only handle 8 users under UNIX, almost 20 under RSTS... but nobody wanted to use RSTS. We called it "Really Shitty Time Sharing".

      Some of the guys managed to patch RSTS Basic+ to run under UNIX by taking advantage of the fact that UNIX used the TRAP instruction for system calls and RSTS used the IOT instruction, by cramming an IOT handler into the half a kilobyte DEC had left for the stack at the beginning of the core image to emulate the RSTS calls that Basic+ needed. That way they could upgrade the business school to UNIX and get rid of the last RSTS holdout on campus.

    16. Re:BTDT by jlehtira · · Score: 5, Insightful

      She found that gcc was including libc even when you don't ask for it.

      This is basic knowledge that ANYONE using c should know - that the startup library is linked to so it can find main.

      Okay, and where am I supposed to learn it from? That was new to me, after using gcc for a very long time.

      I'm actually very happy that someone out there told me something that you think I should just know.

      So it wasn't new to you? Don't read it.

    17. Re:BTDT by Anonymous Coward · · Score: 2, Insightful

      Maybe he simply meant "There aren't too many people in the programming world who do anything worth noting, and there are fewer women still in the programming world, so it's pretty cool for her to have done something that people are checking out".

      What you said is like asking a black guy what his favourite food is and him saying "Why? You think I'm going to like fried chicken or something, just because I'm black?!" when you really didn't mean anything about his race specifically at all, you only wanted to know what his favourite food was.

      I personally always like to hear about a woman doing something of note in IT... like the GP said, it tends to be male-dominated, so I like to hear of more and more women getting involved in the field.

    18. Re:BTDT by tixxit · · Score: 2, Interesting

      Not the GP, but I learned this fact when learning about assembly and trying to figure out why we used _start and not main. I also learned all about the C convention of prepending functions with underscores and a lot of other jazz. I even did some of the type of stuff the author did (abusing the ELF file format to shrink a simple program's file size). However, a lot of folk don't learn asm, so I think this article would be pretty cool. It is also significantly better written and more cohesive than most of the crap I read.

    19. Re:BTDT by tomhudson · · Score: 2

      Now you've got me wondering how many people don't really know what their compiler does under the hood ... darn! Oh well, here's a few places to start digging (it's interesting if you stick with it :-).

      Okay, and where am I supposed to learn it from? That was new to me, after using gcc for a very long time.

      You may have noticed that the man page for STDOUT (man 3 STDOUT) states:

      Under normal circumstances every Unix program has three streams opened for it when it starts up, one for input, one for output, and one for printing diagnostic or error messages. These are typically attached to the user's terminal (see tty(4) but might instead refer to files or other devices, depending on what the parent process chose to set up. (See also the "Redirection" section of sh(1).)

      ... and from this we can deduce that, since there were open for you before your call to main() ever gets executed, that there's startup code in there somewhere to open stdin, stdout, stderr, and tie them to 3 file descriptors. In fact, several dead-tree manuals point this out - that the startup code initializes these for you before your code executes.

      ... or man 3p stdin

      At program start-up, three streams shall be predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output).

      Also, there's additional information with man 3 atexit, that indicates that there's cleanup code that has to be executed after your call to exit - this cleanup code has to come from somewhere ...

      And then there's wikipedia: http://en.wikipedia.org/wiki/C_standard_library

      The run-time support provides not only the C standard library functions, but possibly other material needed to create an environment for the C program, such as initialization prior to the invocation of the main function,

      This is stuff like initializing argc, argv, and env so that your program can use them.

      Also mentioned in dead-tree compiler manuals. Or, for example, C Reference Manual, 1991, Harbison, Samuel P and Steel, Guy L, Ch 20 (p358) - 20.1 MAIN. Also, Ch. 15 (page 304) 15.4 STDIN, STDOUT, STDERR - The external variables stdin, stdout, and stderr are initialized prior to the start of an application program to certain standard text streams.

      Playing around with an assembler would also help, but isn't required.

  2. Missing the point by textstring · · Score: 5, Funny

    Interesting, but she does sort of sidestep the whole 'Hello World!' part of a hello world program.

    1. Re:Missing the point by cthugha · · Score: 5, Insightful

      Since the output is the Answer to the Ultimate Question, it necessarily incorporates or encodes every possible output of every possible program, including the string "Hello World!".

      The method for extracting the particular output desired is left as an exercise for the reader.

    2. Re:Missing the point by dzfoo · · Score: 4, Interesting

      After reading the linked article, I thought underwhelmed. Then I read the second article referenced in the summary:
              http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

      Now, that was interesting!

      The strange thing is that the summary seems to imply that both articles are related, which they are most definitely not. The first one seems to be written by a naive noob, who just discovered a nifty trick in gcc. The second one is written by a real Wizard, who shows you how to conjure up some arcane magic to make ELF your bitch.

            -dZ.

      --
      Carol vs. Ghost
      ...Can you save Christmas?
  3. So what? by Anonymous Coward · · Score: 2, Insightful

    Adding a static 11k or so is insignificant for any program which actually does anything useful.

    1. Re:So what? by AmberBlackCat · · Score: 5, Insightful

      Maybe thinking like that is why we have to get 4 gigs of ram to run without slowing down lately. I bet every executable on the hard drive has an extra 11k that somebody thought was insignificant.

    2. Re:So what? by wiredlogic · · Score: 4, Insightful

      Most of the microprocessors in the world today have less than a few 10's of kilobytes of RAM. They tend to do useful things most of the time.

      --
      I am becoming gerund, destroyer of verbs.
    3. Re:So what? by Yosho · · Score: 4, Insightful

      I bet every executable on the hard drive has an extra 11k that somebody thought was insignificant.

      So if you have, say, 1000 open processes, that means your computer is wasting 11 MB of RAM. Such inefficiency!

      Actually, the reason you need 4 GB of RAM is because the programs you're using are far more complex than the ones that people were using when 256 MB was top-of-the-line. You may say, "But all I need is to read e-mail and browse the web!" -- except that nowadays those tasks involve rendering GUIs with Javascript, streaming and playing HD video in realtime, and doing constant full-text indexing in the background so that you can quickly search anything for any phrase. On top of that, in the background your operating system is trying to predict what you'll do next and prefetching blocks from your hard drive into RAM so that they'll already be cached when you actually need them.

      Some of that RAM is honestly being taken up by insignificant chunks of data, but most of it really is being used.

      --
      Karma: Terrifying (mostly affected by atrocities you've committed)
    4. Re:So what? by rolfwind · · Score: 2, Insightful

      So if you have, say, 1000 open processes, that means your computer is wasting 11 MB of RAM. Such inefficiency!

      When even modern processors have single megabytes of L3 cache, and less L2/L1 cache - it will make a difference if you're swapping from that to RAM constantly.

    5. Re:So what? by swilver · · Score: 2, Insightful

      It will be completely unnoticeable, even if you had a stopwatch.

      Not only is this easy to see theoretically, as most programs will spend the bulk of their CPU time in tight loops, which obviously will be cached the first run through... but it's also easy to see in practice, for example, when processor performance with different cache sizes is compared.

      Multitasking is probably one of the worst things imagineable for processor caches, yet even with 1000's of context switches every second the difference between a single tasking machine and a multitasking machine will be hard to notice on modern hardware.

  4. Re:Hello World by Megaweapon · · Score: 5, Funny

    FYI, Steve Jobs came up with the idea for the "Hello World" app.

    He also holds the design patent on the touch wheel interface for it.

    --
    I'm sure "SlashdotMedia" will improve on all the wonders that Dice Holdings blessed us all with
  5. Old news is VERY OLD by deblau · · Score: 5, Informative
    --
    This post expresses my opinion, not that of my employer. And yes, IAAL.
    1. Re:Old news is VERY OLD by shird · · Score: 5, Informative

      Indeed, this is very old news, it's been done many times before. I recall reading and applying this article for Windows many years ago:
      http://msdn.microsoft.com/en-us/magazine/cc301696.aspx

      there's also: http://www.ntcore.com/files/SmallAppWiz.htm and http://www.phreedom.org/solar/code/tinype/ (again for windows) and many more.

      --
      I.O.U One Sig.
    2. Re:Old news is VERY OLD by Gamma747 · · Score: 4, Interesting

      It was uploaded to Reddit 12 hours ago; that's probably why it's just reaching Slashdot now.

    3. Re:Old news is VERY OLD by ktappe · · Score: 2, Informative

      November 1999. Slow news day much?

      That would explain why as I followed the exercise along in my terminal, I got this warning:

      "ld: warning: option -s is obsolete and being ignored"

      A decade obsolete as it turns out. I suppose when PC's started measuring their RAM in gigabytes, there was little need to strip executables anymore. Still, the article was a very fun read and took me back to the 80's when I was programming at the byte level myself. See also: One-line programming contests and the like. Much more fun (to me) than today's object-oriented everything.

      --
      "We can categorically state we have not released man-eating badgers into the area." - UK military spokesman, July 2007
    4. Re:Old news is VERY OLD by ta+bu+shi+da+yu · · Score: 2, Funny

      ... and I read it in 2002. On slashdot.

      --
      XML is like violence. If it doesn't solve the problem, use more.
  6. Nice but? by garcia · · Score: 4, Insightful

    Ok, this is wicked great in theory. Our programs have become bloated. We do have them taking up too much RAM, HD space, and CPU time. But after reading through this in-depth analysis I have to wonder if it's all worth it.

    If we're willing to leave behind all pretenses of portability, we can make our program exit without having to link with anything else. First, though, we need to know how to make a system call under Linux.

    Or I can just write it the old way, making the file size larger and not have to concern myself with portability and how to make system calls under Linux. After all that's what the whole point of this all was right?

    1. Re:Nice but? by dido · · Score: 4, Insightful

      Which is missing the point. Haven't you ever wondered what's really in that 11k of machine code, and what it actually does? We've gotten so insulated from the lower levels of our computers that we no longer really understand how they do something so basic as terminating their own execution. The article felt more to me like an expository attempt to shed light on some of the things that libc has to do for us, rather than practical advice on attempting to make our programs smaller.

      --
      Qu'on me donne six lignes écrites de la main du plus honnête homme, j'y trouverai de quoi le faire pendre.
    2. Re:Nice but? by fermion · · Score: 3, Insightful
      I disagree that programs are bloated. In most cases, we code to deliver a product at a reasonable cost. Competent trained humans are much more expensive than gates. This is why few people code in C. They want fancy features like trash collection, signaling, and GUI. While all of these can be custom coded on a case by case basis so that only the features needed are included, and the libraries are optimized. Of course competent programmers do not need trash collection, but it sure makes life easier, and can cut down on programming hours. So we tolerate a bit of inefficiency because, frankly, very few people are going to pay double the price so they can use a 500 MHz 256B computers. The average person is more likely going to pay $400 for a 2 GHZ @GB machine, and then want the software for little or no money.

      Now, that is not to say the libraries should not be optimized. It makes economic sense to spend significant time on such code. Just look at MS Vista. But complaining that we unnecessary library code is sometimes included does not really solve any problems.

      --
      "She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
    3. Re:Nice but? by Sycraft-fu · · Score: 3, Insightful

      Well that's part of the REASON that programs have become "bloated." We have plenty of resources these days. RAM and HDD space is cheap. So, it doesn't make sense to spend time trying to wring every byte out of a program. If having a bit of bloat makes the program more portable, or easier to debug, or more resilient to attack or whatever it is probably worth while.

      I'd much rather have a program that was 1MB larger than it needs to be, but easy for the devs to maintain and nice and compatible than one that is as small as possible but is a complete mess at the code level. As a practical matter program data, like graphics, sounds, media, etc, is way, WAY bigger than the program itself. For example Mass Effect 2 has about 25.6MB of code between its binary and various DLLs. If you count system DDLs it uses, it is maybe up to 50MB. It's total size? 12.1GB. All the rest is data of various kinds. They could halve the size of the code and still not make even a tiny dent in disk or memory usage.

  7. I can code that app in... by putaro · · Score: 5, Funny

    45 bytes, huh? I can do it in....

    #!/bin/sh
    exit 42

    18 bytes and it's portable across all Unices. Maybe the assembler version is faster, though?

    1. Re:I can code that app in... by eggled · · Score: 2, Informative

      MUMPS: w 42
      If you want to clear the screen and add a new line: w #,42,!

    2. Re:I can code that app in... by Dynetrekk · · Score: 5, Insightful

      Hm, if I make a file 'hello.py' with the following content:

      print 42

      ...and say to Mac OS X "open .py files in the python interpreter" and double-click, it does the job. In 9 bytes. I guess you can get it shorter if you use a language with a shorter "print" statement / function?

      And how big is Python?

      Granted, but how big is linux, letting you run that ELF?

    3. Re:I can code that app in... by larry+bagina · · Score: 4, Funny

      White pythons are generally 5-8 inches. It's a popular misconception that blacks have larger pythons. In reality, the average black python is slightly smaller than the average white python, but there's much more size variation. Asian pythons are smaller. And then there are some unfortunate guys with a micro python thats only 1-2 inches.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    4. Re:I can code that app in... by putaro · · Score: 2, Insightful

      So did the original - it was launched from the command prompt and the shell was used for the output of the return code. The shell is part of the base OS anyhow, and you can't boot Linux without the shell.

  8. Umm, but by Psychotria · · Score: 4, Insightful

    Since when does a Hello World program not actually output anything?

    1. Re:Umm, but by Psychotria · · Score: 2, Informative

      And I guess if you'd read the blog (the second link in the article not the third) which the summary is actually referring to, you would know that there is no output from the program written by the "MIT programmer [who] decided to make a Linux C program so simple, she could explain every byte of the assembly".

  9. Re:11k Is Too Big? by CapnStank · · Score: 5, Insightful

    I think you missed the point of the article.

    The author is trying to highlight that amount of bloat in modern programs is so rampant that even "Hello World" is excessively over sized for what it accomplishes. How can we as programmers expect fast, efficient, lightweight code when our compiler (even ones as popular as gcc) are bloating the program without being asked to?

  10. If it's so simple, by newcastlejon · · Score: 4, Insightful

    Why doesn't it fit in TFS?

    --
    If God forks the Universe every time you roll a die, he'd better have a damned good memory.
  11. Re:11k Is Too Big? by exasperation · · Score: 5, Insightful

    As to the point of this... we recently had a story about how computers had gotten "too big to understand".

    And here we have a program, 45 bytes long, for which every single byte has a well-explained purpose. It's getting back to the bare metal and that's what makes it interesting. =)

  12. Similarly by McBeer · · Score: 2, Interesting

    Awhile back I read another similar article. In the article the smallest PE created is a bit larger (97 bytes), but a little more standards compliant. More interestingly, however, the author crafts a program that downloads and executes another program in only 133 bytes.

    --
    Hikery.net - The best hiking site ever. Made by yours truly.
  13. IEFBR14 by kenh · · Score: 4, Interesting

    Mainframers have been using this most simple of all utilities for decades - literally. The Wikipedia entry on it has a good write-up about this (literal) do-nothing program. It's whole purpose is to provide a mechanisim to to exploit the various functions contained in JCL to create, delete, and otherwise manipulate datasets on mainframes.

    The wikipedia entry is here: http://en.wikipedia.org/wiki/IEFBR14

    --
    Ken
    1. Re:IEFBR14 by craighansen · · Score: 3, Interesting

      The original bug in IEFBR14 was that it didn't set the exit code to zero. Fixing that bug doubled the size of the program (from one instruction to two).

  14. Simpler "Hello World" in C? by kenh · · Score: 5, Insightful

    At the end, the code was assembler, and the compiler wasn't even called - just the linker. I can't say for sure where a C program ends and an assembler program begins, but I'm fairly certain that the last few iterations are assembler, based on the "let's do away with the compiler" suggestion.

    Also, "Hello World" programs have to, you know, actually display the message "Hello World" - this is a program that isn't written in C, and doesn't write "Hello World" - care to revisit the title of this entry?

    --
    Ken
    1. Re:Simpler "Hello World" in C? by MerlynEmrys67 · · Score: 3, Interesting
      I always liked the "Strangest Abuse of the Rules" catagory winner for Hello World
      char*_="Hello world.\n";

      That is it - the whole program.

      --
      I have mod points and I am not afraid to use them
    2. Re:Simpler "Hello World" in C? by refactored · · Score: 2, Informative
      Parent said, I always liked the "Strangest Abuse of the Rules" catagory winner for Hello World

      char*_="Hello world.\n";

      That is it - the whole program.

      echo 'char*_="Hello world.\n"; ' > a.c
      $ gcc a.c
      /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
      /build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
      collect2: ld returned 1 exit status

      Doesn't say "Hello" to me!

    3. Re:Simpler "Hello World" in C? by onefriedrice · · Score: 3, Interesting

      Parent said a lot of words...

      But missed the point: http://www2.latech.edu/~acm/helloworld/c.html

      "This program is (supposedly) the smallest C program able to print "Hello world.". The compilation itself produces the desired printout and the program need not be actually run."

      --
      This author takes full ownership and responsibility for the unpopular opinions outlined above.
  15. Something similar by crow · · Score: 2, Interesting

    I had a laptop that was really short on memory back in 1996 or so. I liked having the six virtual consoles, but rarely used them, so I wrote a program that would wait for you to press enter, then exec the regular login program. It copied the executable onto the same page as the stack and had no globals, so at run time, it used exactly one page of RAM. I used the same technique as the author here of calling syscalls directly instead of using libc.

  16. Re:11k Is Too Big? by WrongSizeGlass · · Score: 3, Insightful

    I understand the point of the article, and everything else mentioned here. I just think that the amount of time spent eliminating 11k from a program in this case is irrelevant because any real application is going to need libc. It's not like she needed to strip it out so it would fit inside a tiny corner of an embedded processor - she's probably running it on a PC with anywhere from 1GB - 4GB of RAM.

  17. YES!!!! FINALLY by commodoresloat · · Score: 5, Funny

    Thank God we have finally crossed this hurdle. The baffling complexity of helloworld.c is no longer an obstacle to world domination.

    I think we can now finally say once and for all that 2010 will be the year of Linux on the desktop.

    1. Re:YES!!!! FINALLY by Aphoxema · · Score: 2, Funny

      Thank God we have finally crossed this hurdle. The baffling complexity of helloworld.c is no longer an obstacle to world domination.

      I think we can now finally say once and for all that 2010 will be the year of Linux on the desktop.

      No it won't. Do not be foolishly optimistic. Until videogames are readily available on Linux (and I mean commercial games like Call of Duty), no general consumer would be compelled to use Linux on Desktop (may not apply for netbooks).

      *sigh*

      --
      "Most people, I think, don't even know what a rootkit is, so why should they care about it?"
  18. Re:11k Is Too Big? by Anonymous Coward · · Score: 4, Informative

    The whole point was learning ELF structure and why things were they way they were. Didn't you ever wonder why a "hello world" program took over 4000 bytes on a modern computer, when in 1980 a Commodore VIC-20 managed to play games in less than 4K of available memory? This wasn't a waste of time.

  19. Stoner code. by geekmux · · Score: 3, Funny

    OK, when I first read this, I thought to myself, "now why in the hell would anyone care to do this?"

    Then it dawned on me. One stoned programmer said to another....Yeah, that's probably how it went down. Both now, and back in 1979, when you could still smoke in the Data Center...

  20. Re:11k Is Too Big? by gzipped_tar · · Score: 5, Insightful

    But my stupid build process that generates the bloated Hello World is much more maintainable. Now get off my lawn.

    --
    Colorless green Cthulhu waits dreaming furiously.
  21. Re:11k Is Too Big? by Simonetta · · Score: 4, Interesting

    "An 11k app is not going to make me, or my computer, say 'Good Bye World'"

      It is if your computer is a 38-cent Atmel AVR tiny 10, which only has enough space for 512 12-bit instruction words. This chip is about half the size of a sunflower seed, but is faster, and, in several ways, more powerful, than the original $5000 IBM PC from 1981.

      Get away from the idea of Gigahertz desktops and $1000 laptops and join the real computer revolution!

        For me, if it costs more that $5, it's not a computer that I take seriously. It's just a 20th-century digital processing appliance.

  22. C++ is worse by MobyDisk · · Score: 4, Insightful

    Shouldn't the linker remove unreferenced functions?

    I've had this problem with gcc for a while, with C++ code. I was writing some embedded code, and I wanted to use some simple C++. Just by adding a #include of one of the stream libraries. the executable grew by 200k, even though none of it was referenced. The C++ code in iostream is template-generated anyway, so even if the compiler wanted to include the code, it can't until I instantiate it.

    1. Re:C++ is worse by macshit · · Score: 5, Informative

      Shouldn't the linker remove unreferenced functions?

      I've had this problem with gcc for a while, with C++ code. I was writing some embedded code, and I wanted to use some simple C++. Just by adding a #include of one of the stream libraries. the executable grew by 200k, even though none of it was referenced. The C++ code in iostream is template-generated anyway, so even if the compiler wanted to include the code, it can't until I instantiate it.

      <iostream> includes references to global stream objects like std::cout, not just interface definitions, so including it's going to have larger ramifications that something like <fstream>, which just defines interfaces (and indeed, for me, including <fstream> seems to have no effect on program size, whereas including <iostream> adds about 300 bytes to a simple executable).

      --
      We live, as we dream -- alone....
    2. Re:C++ is worse by ShakaUVM · · Score: 2, Insightful

      Shouldn't the linker remove unreferenced functions?

      I've had this problem with gcc for a while, with C++ code. I was writing some embedded code, and I wanted to use some simple C++. Just by adding a #include of one of the stream libraries. the executable grew by 200k, even though none of it was referenced. The C++ code in iostream is template-generated anyway, so even if the compiler wanted to include the code, it can't until I instantiate it.

      There's utilities you can run to pull unused object code out of your file, to make the executable smaller.

      But in general, if you are care about a 300k increase in your executable, you should probably be using C anyway.

  23. Re:Occams Wedge by Arker · · Score: 4, Insightful

    But it really is much simpler. The reason your 'average first year comp sci student' might find it less understandable is because they dont actually understand the bloated version either. Using a high-level language doesnt reduce complexity, quite the opposite in fact, it greatly increases actual complexity. It simply makes it easier to get something done without understanding it, and thus makes it easier to kid yourself into thinking you know what you are doing, when you dont.

    --
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Friends don't let friends enable ecmascript.
  24. Re:11k Is Too Big? by TyFoN · · Score: 2, Informative

    This is because we are no longer linking the binaries statically (one object file for each function), but are using dynamically linked libraries. And your libc is't loaded only for your program. The same spot in ram is shared between all programs that are using it making the total ram spent for each program rather small, probably even smaller than if you would statically link the object files of the functions you need.

  25. OK, now generalize that by istartedi · · Score: 2, Insightful

    Patch the strip utility on Linux, send in the patch and see if it gets accepted. Then let's see a follow-up of that on Slashdot. She's taking a lot of flack here; but there's value in the work. It just needs to be applied in a more practical way.

    --
    For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
  26. Re:11k Is Too Big? by jc42 · · Score: 4, Insightful

    Yeah, but the 45-byte program doesn't say "Hello World". In fact, there's no example that I can find in TFA that outputs that message or any other. So the summary is incorrect on its face. TFA doesn't show a simpler "Hello World" program; it doesn't show any sort of "Hello World" program at all.

    I feel cheated, and tricked into reading an article that didn't do what was advertised.

    (It's not the author's fault, of course; the author didn't claim to be writing the sort of program that the summary talked about. Though I was a bit disappointed that only the first few examples were in C. The article was almost entirely about assembly-language programs. So again, I was a bit disappointed, since I was hoping to learn something about making C programs smaller. This was done only in the first example, and it was made smaller by removing its call on write() so it didn't output anything at all. I already understood that I can make programs smaller by removing all functionality. ;-)

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  27. Re:Hello World by thegrassyknowl · · Score: 5, Funny

    No Steve Jobs designed "iHello World", which is actually one byte larger than the standard hello world app, but he's litigating against everyone who creates "Hello World" since 100% of it is quite obviously a subset of "iHello World".

    --
    I drink to make other people interesting!
  28. Not a C program by erroneus · · Score: 4, Informative

    I wasted too much time reading this one... nothing surprising about what I found in it. Step one, don't write it in C. Step two, stop linking to things that aren't needed. Step three, perform the functions contained in the library omitted manually. Step five, start cheating in the elf binary format.

    The only thing interesting about it was that the article pointed out an interesting fact -- Linux will run inappropriately formatted binaries. BAD. Linux kernel people? Are you reading this? Fix it before someone figures out how to use this in making and executing more exploits.

  29. Re:11k Is Too Big? by VocationalZero · · Score: 2, Funny

    It's just a 20th-century digital processing appliance.

    Mine is a 21st-century appliance, thank you very much!

  30. Damn kids by ucblockhead · · Score: 2, Informative

    Back in the DOS days, any moderately competent programmer knew how to copy arbitrary data to screen buffer, allowing you to display text without any libraries. It's been many years, so I am probably getting this wrong, but in psuedocode it'd look something like


    char*cp="Hello World";
    char *addr=0xB8000000;
    while(*addr++ = *cp++);

    That's the C version, of course. You'd actually do it in assembly. My suspicion is that you could do it in on the order of 20 to 25 bytes, but again, it's been decades since I've done anything like that.

    --
    The cake is a pie
    1. Re:Damn kids by mandelbr0t · · Score: 2, Interesting

      mov bx, 0xB000
      mov es, bx
      xor di, di
      mov si, OFFSET msg
      mov cx, LEN
      stosb

      .data
      msg db 'Hello, World!', 13, 10, $
      LEN equ 15

      I wasn't blessed with a color card. And I'm sure that's not actually any real dialect of assembly, but you get the picture.

      --
      "Please describe the scientific nature of the 'whammy'" - Agent Scully
  31. Still written (mostly) in C. . . by JSBiff · · Score: 2, Interesting

    "At the end, the code was assembler"

    But, the key point is that the user didn't generate that assembly. The user wrote a C program (granted, the program doesn't actually do any output - it just stores a string in memory, then exits). The user called the compiler to compile the program. The user then *disassembled* the object code which was created by *the compiler*. So, the assembly you see was generated (indirectly, via the objdump command), by the C compiler.

    Exception: the user did create a small assembly file with the place-holder _start function. Perhaps, this example would have benefitted by the user defining the _start() function in C also, and using the compiler to compile that - not sure if that actually would have worked or not, but would have been interesting if she had tried.

    One other point I'd like to make - ultimately, every C program has to have some assembly *somewhere*. When you call the printf(), printf itself either must use some assembly to interact with the operating system (in order to cause output to be sent to stdout), or printf *might* punt that off to another function, which then has some assembly inside it. The only reason you can do *any* input or output in C (or any other language for that matter) is that, at some point, somewhere, either in the compiler itself, or in a standard library, someone has provided the necessary assembly code for you.

    In the case of C, the language designers decided to make the C-language pure 'logic', without any notion of input or output statements, or operating system interactioni, and do all input/output/system calls via library functions (whether you use the standard library, or a 'third-party' library [ I use the term third-party loosely here, because the 'third-party' lib might actually be provided by your compiler vendor, but it's just not the standard library]).

  32. Re:11k Is Too Big? by ucblockhead · · Score: 4, Insightful

    The fact that helloworld.c compiles to 11k has less to do with bloat than it has to do with people generally not caring about 11k. You could get rid of that 11k, but to do so, you'd have to make trade offs that either make real programs either slower or bigger, or make compilation slower. Very few people would make those trade offs in the other direction. Those that do either use special purpose compilers or (more likely) write in assembly.

    --
    The cake is a pie
  33. Re:11k Is Too Big? by Zouden · · Score: 4, Funny

    Get away from the idea of Gigahertz desktops and $1000 laptops and join the real computer revolution!

    You're right! I'm going to throw my laptop out the windows right now! Reading slashdot will be so much more fun on a computer smaller than a sunflower seed.

    --
    "A week in the lab saves an hour in the library"
  34. Re:11k Is Too Big? by Schraegstrichpunkt · · Score: 3, Informative

    These days, costs of development and deployment, not runtime memory usage, are the limiting factors in software development.

  35. That's exactly it by Anonymous Coward · · Score: 4, Funny

    Guy reminds me of an old joke.

    What's the difference between a bitch and a whore?

    A whore fucks everyone. A bitch fucks everyone but you.

  36. Bare metal DOS? by blueg3 · · Score: 3, Insightful

    If you're actually programming on "bare metal", you're not really using DOS, are you? After all, DOS is an operating system -- a layer between your code and the hardware.

  37. Let the lawn derby begin by ClosedSource · · Score: 3, Funny

    One of the earliest processors I used had only 256 bits of RAM (Yes, that's right 256 B I T S of memory)

  38. Re:11k Is Too Big? by walshy007 · · Score: 4, Interesting

    #hello world tiny program
    .equ SYSCALL, 0x80
    .equ SYS_EXIT, 1
    .equ SYS_WRITE, 4
    .equ STDOUT, 1

    .section .data
    hello:
    .ascii "hello world!\n"

    .section .text

    .globl _start
    _start:
    movb $SYS_WRITE, %al     #put write syscall in eax
    movb $STDOUT, %bl     #set stream to stdout
    movl $hello, %ecx #give address of start of buffer to print
    movb $13, %dl     #how many characters of buffer to print
    int $SYSCALL
    movb $SYS_EXIT, %al
    int $SYSCALL

    The above is a tiny hello world program i wrote myself, it's worth noting that even the resulting binary is larger than it needs to be, I wound up with a 133 byte binary by moving the text string into the ELF header via hex editor, and changing the instruction data to point to the new addresses.

    Kind of hard to get it smaller than that while keeping it in ELF format, considering the actual object code in the binary was something like 15 bytes with the data illegally in the header.

  39. Re:11k Is Too Big? by MachDelta · · Score: 4, Insightful

    TFA explains it: main() isn't the true start of the program, _start is. That resides in ctrl.o, which fires off a bunch of setup stuff before calling __libc_start_main, which in turn kicks off main(), and off your program goes.

    To put it as a car analogy: What she found is that turning the key to start doesn't just activate the starter, it also activates the airbag system, the traction control, and the radio too. And if all you want to do is start the engine to prove that it runs (ala Hello World!), then it's kind of silly to lug around all that extra "unnecessary" crap too.

    Or something like that. Sadly i'm a better mechanic than a programmer (4yrs vs 1yr), but i'm working on fixing that. :)

  40. +5, Insightful by aussersterne · · Score: 5, Insightful

    Mod parent up. This is all a semantic game about where significant portions of functionality are stored (and thus counted or not). After all, back in the "pre bloatware" days, you'd have had to manage all of the complexities of machine management and I/O yourself. The assembly would have been much larger to achieve the same effect.

    Yes, you can make the argument that Linux comes with screen I/O, a scheduler, memory management, etc. already, so that's just overhead, but as others have pointed out, you can say the same thing about bash. It comes everywhere and is just overhead.

    --
    STOP . AMERICA . NOW
  41. 29 bytes ! Beat that !!! by Anonymous Coward · · Score: 5, Interesting

    c:\ xxx>debug
    -a
    mov dx, 100
    mov cx, 000D
    mov bx, 1
    mov ah, 40
    int 21
    mov ah, 4C
    int 21
    -f 111 "Hello World!"
    -a100
    mov dx, 0111
    -r cx :001D
    -n c:\ xxx\ hello.com
    -w
    -q

    c:\ xxx>hello.com
    Hello World!

    c:\ xxx>dir hello.com
    03/18/2011 11:29 AM 29 HELLO.COM

    1. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 2, Funny

      But you're including that bloated library DOS. Much better to bypass all that cruft and just use the hardware directly. Also, why write the whole string. The user will just have to know that 'h' stands for hello world. It's a training issue!

      mov ax,0b800h
      mov ds,ax
      xor di,di
      mov byte ptr[di],'h'
      ret

    2. Re:29 bytes ! Beat that !!! by Eil · · Score: 2

      03/18/2011 11:29 AM 29 HELLO.COM

      Nice to see people still use DEBUG.EXE in the future!

  42. Re:11k Is Too Big? by santax · · Score: 5, Insightful

    Try programming a micro-controller and suddenly you'll be facing hardware limits that force you to favor small unreadable code over bigger more maintainable code. There is a solution for it though... comments! Lots of them :D

  43. Re:11k Is Too Big? by siride · · Score: 2, Insightful

    Doesn't matter anyways because demand paging ensures that only the parts of libc that your program actually uses will be pulled into memory, so all the extra junk will remain on disk.

  44. Re:11k Is Too Big? by mirix · · Score: 4, Informative

    gcc for an AVR target doesn't make an 11k hello world, though.

    Probably because that's an application where it matters, and a modern PC it doesn't matter at all.

    --
    Sent from my PDP-11
  45. The summary headline is crap by jamrock · · Score: 4, Informative

    There are three links in the article summary. The first is to the Wikipedia entry for "Hello World"; the second is to an article about writing "Hello World" without libc; the third is to part II of the second, an examination of the ELF format and demonstrates the 45 byte program. The summary headline is rubbish. Whoever wrote it either (a); never read either article, or (b); deliberately sensationalized it by conflating the salient features of both articles, in which case they should be working for the tabloids.

  46. Did similar back in MS-DOS 2.11 by Brett+Johnson · · Score: 4, Interesting

    Back in the early 1980s, I was doing development on MS-DOS 2.11 - the first real working version of MS-DOS that resembled Xenix more than CP/M.

    I was using a combination of Lattice C and assembly language to do my day job. But I was upset about the libc bloat that Lattice C would drag into the program. Over the Christmas break, I sat down and wrote a tiny version of libc, with the 60% of the calls I actually used. Most of them were either thin wrappers on top of MS-DOS Int21 calls, assembly language implementations (the string functions), or reduced functionality (printf didn't handle strange alignments, floats or doubles), and custom startup/exit code. I also structured the library so that the linker would only link in functions that were actually used. For simple executables, I saw the on-disk file size drop from 10KB-20KB down to 400-600 bytes. Another thing that reduced on-disk file size was to create .com programs, rather than .exe programs.

    I was also writing the handful of unix commands that I couldn't do without (ls, cat, cut, paste, grep, fgrep, etc). Since I was implementing dozens of Unix commands, each statically linked to libc, it was very important to reduce the over-all size of each executable. Most of the smaller trivial commands were less than 1KB in size. I think the largest was 4KB. I also had an emacs clone* that was 36KB when compiled and linked against my tiny lib.

    For the longest time, I carried around a bootable MS-DOS 2.11 floppy, with my dozens of Unix commands, an emacs-like editor, Lattice C compiler, tiny libc, and some core MS-DOS programs. It allowed my to have my entire development environment on a floppy that I could stick in anyone's machine and make it usable.

    * We had a source license for Mince, orphaned by Mark of the Unicorn, a tiny emacs-clone that ran on CP/M, MS-DOS, and Unix. We had enhanced it significantly.

    1. Re:Did similar back in MS-DOS 2.11 by AceJohnny · · Score: 2, Interesting

      I've always wondered: what was the difference, in DOS, between a .com and a .exe?

      --
      Misleading titles? Inflammatory blurbs? Keep in mind that Slashdot is a tabloid.
  47. Re:11k Is Too Big? by PakProtector · · Score: 3, Insightful

    OOP makes people lazy and gives them less of an understanding of what's actually going on.

    All that OOP code you write gets translated back into something procedural, you know.

    --

    Edward@Tomato - /home/Edward/ man woman
    man: no entry for woman in the manual.
    "Qua!?"

  48. Re:11k Is Too Big? by blackraven14250 · · Score: 3, Insightful

    It's funny that this always come up in conversations about bloat, because not everyone has to program for embedded code, because not everyone is programming embedded devices. It's almost like you guys are a subsubculture of programmer, to the point where many of you guys come off with the general attitude of being superior, when in fact, neither approach is superior, just different based on the situation.
    /rant

  49. Re:11k Is Too Big? by santax · · Score: 3, Interesting

    Hmmz, I was hoping my post was without any judgement about what is 'better' and more '133t' coding. Sorry you think otherwise :(

  50. Re:11k Is Too Big? by crazybit · · Score: 3, Insightful

    Not only more maintainable, but filesystems should use 4k per sector, specially on raid's for performance stuff discussed on this post. This means that in a decently configured modern system, anything under 4k will still occupy 4k on disk.

    --
    - Human knowledge belongs to the world
  51. Apple defines system call APIs at the top of libc by tlambert · · Score: 3, Informative

    Apple defines system call APIs at the top of libc ...no static linking allowed.

    This annoys people who like to link things statically, and those who want to make their own libc equivalents for things like embedded language interpreters and don't want to have to figure out vtables and dynamic linking.

    But it also makes everyone else who likes binary compatibility, and Mac OS X historically getting faster with every release, extremely happy, by allowing the interface between the kernel and libc to be changed, without breaking their applications.

    If you statically link, you can't do that. That's great, if your OS has pretty much no real commercial application base, and you are a technical enough person to "just recompile everything from source", but it's not so good when you are talking about an OS where commercial software is very important to customers. Customers who are either non-technical, or who are technical, but think recompiling something that was working just fine before the OS update is a complete waste of time. Lump me in with these last people: I don't believe in "bit rot", I just believe in lazy engineers not maintaining their code or defining their interfaces properly.

    Yeah, if you want fast LMBench results on a null system call -- which keeps changing its definition so that it can't be gamed, exactly the same way you'd game it if you were a commercial application developer needing higher performance -- static linking seems great. But practically, most modern software is either CPU bound or I/O bound. If it's CPU bound, it spends all its time in user space, not making system calls. If it's I/O bound, it spends all its time waiting for whoever is on the other end of the network to send it more bytes. Either way, null system call performance is, frankly, unimportant to almost every possible application.

    So static linking, and writing your system calls at the trap/sysenter/syscall level (with no way to change them when Intel or another chip vendor introduce a "new! optimized method of making system calls!", as has already happened twice in the past) is generally a pretty useless exercise.

    -- Terry

  52. Re:Occams Wedge by Arker · · Score: 2, Insightful

    It hides the increased complexity from the programmer.

    That is what I said.

    Which resources do you think are the most valuable?

    That is not a question for which a single good answer can be given, other than "it depends." There are so many variables. Just how often will how many processors do extra work (that will allow you to calculate the lost electricity - it is a real and calculable cost.) RAM usage also has real costs associated, including electricity, but calculating the final price tag is far more complicated there. But the bottom line is that it is way too much work to really track down and calculate to the penny the costs of innefficient code, even in the narrowest of sense, so no one does. We just sort of guess-timate, and we work within systems that dont encourage us to account for costs that can be passed on unaccounted for, so we generally do it in that manner. That the outcome is naturally for many actors to weigh the decision purely in terms of their own personal and immediate costs and benefits (15 minutes of my time vs. small performance hit to whomever uses) without accounting at all for many less personal and less immediate effects.

    And often enough that works just fine. But there are cases where it will bite you hard. Knowing which situation is which is important. How are you going to do that if you only know quick-and-cheap method without understanding the larger picture?

    --
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Friends don't let friends enable ecmascript.
  53. Mine is simpler by assert(0) · · Score: 2, Interesting

    /* -*- coding: utf-8-unix -*- */

    #include <stdio.h>

    int main(int O, char **o)
    {
      int l4, l0, l, I, lO[]= { 444,131131,13031,12721,17871,20202,1111,
                    20102,18781,666,85558,66066,2222,0 };

      for(l4=0;l4<14;++l4){
        for((l=l0=lO[l4])&&(l0=-7);
        l>4&&(I=2-((l|l>>O)&O));l=l&O?l+(l<<O)+O:l>>I,l0+=I);{
          putchar(10+l0);
        }
      }

      return 0;
    }

    --
    (founded 95,000,000 yrs ago, very space opera)
  54. Re:11k Is Too Big? by Anonymous Coward · · Score: 3, Informative

    Hello (World). I am from the future. The code you have provided a link to will not run on Windows 9.

  55. Re:11k Is Too Big? by mwvdlee · · Score: 2, Funny

    Indeed.
    At 11kB each, my 1TB harddrive would only fit some 97 million programs.

    --
    Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
  56. And so he should! by TheVelvetFlamebait · · Score: 2, Funny

    "Hello World" uses over 90% of his "iHello World" work. You would be hard pressed to make a fair use argument here. ;-)

    --
    You know, there is a difference between trolling and pointing out the flaws in your reasoning. Just saying.
  57. Hey, I heard that Windows isn't the only OS... by N0Man74 · · Score: 5, Insightful

    It's too bad with all these things you "heard" that you didn't happen to hear that programs are written for environments other than Windows (or Linux, Mac OS, etc), and for devices other than PCs. It's unfortunate that you are so in the dark that you don't realize that there are entire industries that rely on devices that have tiny fractions of the memory and processor speed that you ignorantly assume that we all have access too. You probably have no idea how often you are affected by devices that run 100 times slower than the desktop PC you gave as an example, or also have 1,000 times less RAM. On some of these devices C is the most advanced language you can get short of writing a compiler or interpreter yourself.

    Sure, pissing away storage space and waving a hand at execution efficiency is fine for some circumstances, but sometimes it's a luxury you can't afford. The world of software development is far bigger than the tiny little niche of programming you've been exposed to.

    I suggest you use some "real" perspective, and reevaluate what a "real language" is.

  58. Re:11k Is Too Big? by TapeCutter · · Score: 2, Insightful

    "OOP makes people lazy and gives them less of an understanding of what's actually going on."

    I've noticed that people who critise OOP rarely understand what it is and tend to think it's tied to a particular type of language. OO is a way of thinking about a problem at a higher level than functional decomposition. You can code an OO solution in whatever language you like. Done properly it leads to elegant solutions eg; many of the examples in K&R exhibit the features of OO design and they were created before the term "object orientated" was coined. I assume when K&R used function pointers as elements of a struct they "understood what's going on", right?

    "All that OOP code you write gets translated back into something procedural, you know."

    Perhaps that's because...you know...OOP is procedural.

    --
    And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  59. Re:11k Is Too Big? by tomtomtom777 · · Score: 2, Funny

    One of the earliest machines I learned programming on only had 256 bytes of memory.

    You lucky bastard.

    My parents could never afford such computer. I had to learn programming on a computer with only 1 bit of memory (Yes that's right: 1 B I T of memory!)

    Those were the days. And you tell the kids these stories and they won't believe you...

  60. Re:11k Is Too Big? by Tim+C · · Score: 4, Funny

    My God, are you saying that people should use the right tools and techniques for the job at hand, rather than applying the same limited ones to every problem they come across?

  61. Re:11k Is Too Big? by WWWWolf · · Score: 2, Informative

    The whole point was learning ELF structure and why things were they way they were. Didn't you ever wonder why a "hello world" program took over 4000 bytes on a modern computer, when in 1980 a Commodore VIC-20 managed to play games in less than 4K of available memory? This wasn't a waste of time.

    Yeah.

    To put this in perspective: Guess how big the executable header is in 8-bit Commodore machines?

    2 bytes. The absolute start address of the program. The computer opens up the file, reads where it's stored, and starts putting data to the memory from that point onward. Simple enough. Of course, there's none of this "relocation" and "memory protection" rubbish to worry about.

    If you wanted to store program in BASIC RAM, you could write a stub BASIC program that basically just has one code line, 10 SYS<startaddr>, where <startaddr> points to the address past the end of the program in BASIC RAM. In total, this "header" is just a dozen bytes or so in tokenised BASIC. (Don't have the time today to test how small I can make it, but...)

  62. Re:11k Is Too Big? by fyngyrz · · Score: 2, Funny

    Now, get off my lawn!

    ...he can't, he didn't include libc. The thing won't actually move, it just runs. :)

    --
    I've fallen off your lawn, and I can't get up.
  63. Re:11k Is Too Big? by SharpFang · · Score: 3, Interesting

    ...besides, high-level programmers often underestimate just how big a sector embedded programming is. The $IDIOTS_PET_LANGUAGE is for a PC. Now get me more RAM and better CPU for all the devices running embedded software, that are in my sight range as I look around:

    - my cell phone.
    - 6 different monitors (OSD doesn't happen magically. Something remembers the settings...)
    - a videoserver
    - 2 cheap switches
    - a regulated power supply
    - a heat-controlled soldering iron
    - a regular phone
    - 3 PC keyboards (hey, neither PS2 nor USB protocols happen by themselves)
    - 3 computer mice (optical, meaning pretty advanced image analysis)
    - my hand watch
    - a battery charger
    - a USB hub
    - a security motion sensor
    - an MP3 player
    - a webcam
    - a multimeter
    - a car alarm remote
    - a pendrive.

    These all were programmed either in VHDL, Asembler, or C. The phone has some J2ME code too. Think of upgrading each of these devices so much that its firmware could be rewritten in, say, Perl. Or C#.

    Also, think about how much embedded programming is in every PC. Each device controller has its own firmware... my bet is any average house contains more embedded programs (in embedded devices) than PC applications on the "family PC" and stored on media.

    High-level programming languages are nice and have their place, but considering embedded "a niche not worthy of attention" is a bad mistake. The proportions between amounts of server:desktop:embedded software are much closer to 1:1:1 than most "high-level" programmers are willing to admit.

    --
    45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
  64. It won't remove them unless you tell it to by Chemisor · · Score: 2, Interesting

    You have to explicitly enable function-level linking with gcc. Compile your source files with -ffunction-sections -fdata-sections, and then pass -gc-sections flag to ld (-Wl,-gc-sections if linking with gcc). This puts every function into its own .text.section and allows the linker to prune the ones that are not referenced. The remaining ones are coalesced into a single .text section.

  65. Devices by Anonymous Coward · · Score: 2, Interesting

    Here we still program in C (I don't, but others here do) because if we wrote in something like .NET, Ruby or Python the executable would be so much bigger and the binaries wouldn't fit on the device hardware. So sometimes having something 'closer to the iron' is better.

    Then again, when telling a device how to servo, string interpretation is seldom of high concern.

  66. Re:How about 28 bytes?! by bendelo · · Score: 3, Informative

    How about 22 bytes?

    C:\>debug
    -a 0100
    0D39:0100 MOV AH,09
    0D39:0102 MOV DX,0109
    0D39:0105 INT 21
    0D39:0107 INT 20
    0D39:0109
    -e 0109 'Hello world!$'
    -r cx
    CX 0000
    :16
    -n hello.com
    -w
    Writing 00016 bytes
    -q

    C:\>HELLO.COM
    Hello world!
    C:\>dir hello.com
    26/08/2009 10:48 22 HELLO.COM

  67. Re:How about 28 bytes?! by Anonymous Coward · · Score: 2, Funny

    Why did you put it in your porn folder?

  68. Re:11k Is Too Big? by Alari · · Score: 2, Funny

    Nope! Now, hand me that pickaxe, I need to dig myself a memory upgrade.

    http://df.magmawiki.com/index.php/Computing

    --
    I use Windows... like a two dollar wh.. why don't I just go ahead and not finish that sentence.