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!"

582 comments

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

    *sigh*

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

    1. Re:BTDT by MichaelSmith · · Score: 1

      *sigh*

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

      Was that in RSX11-M? I was never exactly sure how that OS hangs together but one interpretation I had was that all libraries and application processes are permanently running processes (or installed images, take your pick). So that there is one copy of the libc equivalent installed in the OS at startup and images which need it jump straight in to addresses inside that image.
      I spent a lot of time building applications into the OS with fingers crossed ;)

    2. 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.
    3. Re:BTDT by Anonymous Coward · · Score: 0

      You so obviously didn't get any.

    4. 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.

    5. Re:BTDT by Anonymous Coward · · Score: 0

      So much for RTFA. oh wait, it's slashdot.

    6. Re:BTDT by Anonymous Coward · · Score: 1, Funny

      Why do you hate women so much? Is it out of self loathing that you had to become one?

    7. Re:BTDT by Have+Brain+Will+Rent · · Score: 1

      Yup me too, on the PDP-8 in 1971. *sigh*

      --
      The tyrant will always find a pretext for his tyranny - Aesop
    8. 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.

    9. Re:BTDT by zoomshorts · · Score: 1

      RT-11 ??

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

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

    11. 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.
    12. 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.
    13. Re:BTDT by guyminuslife · · Score: 1

      Disclaimer: Don't try that. Those things are heavy.

      Also, I wasn't born.

      --
      I don't believe in time. It's a grand conspiracy designed to sell watches.
    14. 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.

    15. Re:BTDT by Anonymous Coward · · Score: 0

      So she's hot, nerdy enough to write articles about writing smaller C programs, AND she's a deranged sex freak? I can see why you're upset you never got with her.

    16. Re:BTDT by Anonymous Coward · · Score: 0

      Brian Raiter is the author in question, and he is a man.

    17. Re:BTDT by Two9A · · Score: 1

      That sounds very similar to what I did back in 2006, on the Nintendo DS. I tried to put together the smallest DS ROM that could actually do something (in this case, turn the screen red):

      http://imrannazar.com/The-Smallest-NDS-File

      I ended up embedding the code in the NDS header, which is 352 bytes long; I don't think it's possible to get a DS ROM smaller than that, but I'd be willing to be proved wrong.

      --
      xkcdsw: the unofficial archive of Making xkcd Slightly Worse
    18. Re:BTDT by clemdoc · · Score: 1

      You mean the fact, that 'SHE' appears in the summary is not enough? Of course, that would require reading the summary.

    19. 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
    20. 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.
    21. Re:BTDT by smallfries · · Score: 1

      Millions of times over the years by millions of people.

      The 57 bytes looks impressive at first, but seriously? Is that using 57 bytes of their own rather than borrowing them from somewhere else? Come back next year and have another go...

      (actually found that while googling for the last slashdot story about overlapping ELF headers to get a smaller hello world)

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    22. Re:BTDT by Have+Brain+Will+Rent · · Score: 1

      But it was dragging the damn extension cord up hill both ways that was the real killer.

      --
      The tyrant will always find a pretext for his tyranny - Aesop
    23. Re:BTDT by smallfries · · Score: 1

      So why does she go by the name Brian? Is this a level of Monty Python in-joke that the rest of us can't even dream of?

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    24. Re:BTDT by Anonymous Coward · · Score: 0
      And I think it's worth pointing out that the author of the the muppetlabs link is a man. I know, reading comments is even harder than reading the summary...

      This subsection of the Muppetlabs website is maintained by Brian Raiter (aka Organic Worker Drone BR903), who is the author of the contents where not otherwise indicated.

    25. 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.

    26. Re:BTDT by AliasMarlowe · · Score: 1

      RT-11 ??

      RT-11 needed a PDP-11 (16-bit cpu). The closest equivalent for the PDP-8 (12-bit) was RTS-8. I never used the PDP-8 for real-time stuff, but did "enjoy" booting it to TSS-8 for multi-user access. The procedure involved a lengthy sequence of messing with the front panel toggle switches accompanied by muttering of curses and magic incantations.
      [adopts faux-Yorkshire accent] And you try to tell that to the young people today, and they won't believe it...

      --
      Those who can make you believe absurdities can make you commit atrocities. - Voltaire
    27. 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.

    28. Re:BTDT by L4t3r4lu5 · · Score: 1

      I've set kdawson stories so they don't show up on the homepage. There's a setting somewhere in your user options.

      I'm only here because I came from an RSS feed, which is unfortunately unaffected by that setting.

      --
      Finally had enough. Come see us over at https://soylentnews.org/
    29. Re:BTDT by Anonymous Coward · · Score: 0

      There's something else C programmers should know...use a real language! Yes, programming fundamentals are extremely important. Yes, people should learn C or C++ first. Yes, old people are going to bitch as usual in response to this thread. But seriously, anyone "still using C" like you said needs to get with it and realize that modern software needs something a little quicker and more flexible. I heard they invented this thing called strings since C came out. Or maybe I should just mail them a modern system spec sheet. I hear they're shipping with 4+ GB of ram and multicore processors these days. I don't care if the .NET control for a timer takes up like 500kb of memory instead of 10, it takes me 1 minute to write a block of code using it instead of ten days of digging through documentation and API notes and crap. The fact that people would even still use C at all for anything anywhere ever shocks me.

      Learn your job and maybe one day you can move up from toy computers with toy operating systems.

    30. 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?
    31. Re:BTDT by gbjbaanb · · Score: 1

      to be fair - TFA is actually quite good. The summary could be a little more descriptive and have less comments that might have seemed a good teaser to people who didn't know this (and hey, there *are* lots of people who didn't know you can't get rid of libc), but... its a good post 'cos of the article.

      I think a lot of people now are coming to /. to read the summary and post, completely forgetting that those summaries are just a quick hint as to which articles you want to go and read. Some, perhaps, you can do without reading TFA - all the 'Microsoft suffers another security flaw' for instance, we don't need to RTFA just to take the piss out of MS!, but the others... they're good articles. Try reading them sometime.

    32. Re:BTDT by Anonymous Coward · · Score: 0

      Your comment is amusing, but, it's a little closer to the truth than you might think. Transwomen generally resent their male-by-birth bodies, although there are more factors than that; for example, having the emotional makeup of a female means you never feel like "one of the guys"---and often you don't want to be one of the guys, particularly with the strange and callous things they can do. Further self-loathing can arise from being seen as part of that group, with everyone assuming certain characteristics of you that you simply do not have, and closed-minded individuals ridiculing you for having characteristics that "guys shouldn't."

      {disclaimer: pre-op transgirl}

    33. 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...

    34. 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.
    35. 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.

    36. Re:BTDT by argent · · Score: 1

      Don't forget the 4k address space and 12 bit words. :)

    37. Re:BTDT by argent · · Score: 1

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

      The fact that people still use oldschool Algol/Simula-style languages instead of fully reflective languages like Lisp and Smalltalk has been shocking me since the '70s... so get used to being shocked. People just can't let go of these high level assemblers like Java and C#.

    38. Re:BTDT by vlm · · Score: 1

      A modern PDP-8 isn't so heavy anymore. Well, I soldered mine together perhaps 5 years ago.

      http://www.sparetimegizmos.com/Hardware/SBC6120-2.htm

      I mostly run OS-8 on mine, just for run.

      --
      "Science flies us to the moon. Religion flies us into buildings." - Victor Stenger
    39. 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.

    40. Re:BTDT by hesaigo999ca · · Score: 1

      I wonder how sits above him and says, yeah KDawson, that sounds interesting,
      or is there no such pier review before being posted on slashdot???

    41. Re:BTDT by hesaigo999ca · · Score: 1

      Spoken like a true non programmer!

    42. Re:BTDT by donscarletti · · Score: 1

      Both my sisters know C and could easily write a hello world program (and have). Of course the binaries they create are larger than 1.3kb, but at least they would print "hello world".

      Not all women write software that does not even perform a simple task correctly and require platform specific hacks to run without segfaulting. I am disappointed by your misogynistic pointing towards her gender to blame this waste of time on her being female, as if no male has ever done something like this. Maybe you think this is just a humorous attempt of "the weaker sex" to try a man's job.

      But sarcasm aside, what you said was pretty patronizing.

      --
      When Argumentum ad Hominem falls short, try Argumentum ad Matrem
    43. Re:BTDT by troll8901 · · Score: 1

      There's a setting somewhere in your user options.

      He doesn't know that, because he doesn't read the manual. Just like me!

    44. Re:BTDT by lenski · · Score: 1

      Heh. I ran many of my CS projects on the PDP-8L in an Industrial Engineering lab rather than the IBM 370/168 upstairs.

      I used a Fortran IV compiler whose compiled output was intended to run directly on add-on floating point hardware. DEC had a floating point emulator for us poor folks so I ran my projects in a virltualized environment on an 8 kword PDP-8L in 1976.

      Upstairs the rich guys with computing center accounts (time was so expensive that one needed authorization to use a real computer) could use either CMS or VM/370 interactively, or OS/MVT. I believe the 370 had the add-on dynamic address translation hardware but cannot prove it.

      Back then, people were exceptionally territorial with their systems and permission to use them.

    45. Re:BTDT by Anonymous Coward · · Score: 0

      And somewhat more impressively for female geeks— geeks in general, really— she's not a fatty.

    46. Re:BTDT by tomhudson · · Score: 1

      Don't be silly. The two articles were written by two different people, one of each sex. They were equally lame. If you look at the comment thread for the previous article, dozens of people slammed it for making false and misleading claims. What next - an article that goes "gee whiz - did you know you can use a hex editor to write binary code directly, without an assembler?"

    47. Re:BTDT by rdavidson3 · · Score: 1

      Your ideas interest me and I would like to subscribe to your architecture diagram

    48. Re:BTDT by bluefoxlucid · · Score: 1

      I've never been like most of the guys around me, but I'm not a chick in a man's body. I don't see girls as objects-- I do want to shove my cock in them, after I get to know them, and on mutually agreeable terms. But they're still people. But hey, female-people like getting screwed, come on, don't kid yourself; they make noise and claw and beg and when you try to get away they demand more.

      Most of the guys I know are all about the one night stands. Lie, cheat, steal, rutheprophenol, lots of alcohol, anything to get some. And they treat the girls like trash. I mean hey I have nothing against having multiple girls that I'm just sleeping with for fun, but come on.

      Apparently guys shouldn't have feelings, cry, or give a shit about how we treat other people. Oh well.

    49. Re:BTDT by Jon+Abbott · · Score: 1

      Some people need their code to run on a microcontroller.

    50. 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.

    51. Re:BTDT by Anonymous Coward · · Score: 0

      Does it bother you that these toys rule the world? You sound like a bitter old dinosaur complaining about the rats while flaming death crashes down from the sky.

    52. Re:BTDT by berashith · · Score: 1

      yes, closer to the metal. I load everything to ram to keep it closer to the metal. the performance hit from the spinning magnets not being directly next to the processor is amazing.

    53. Re:BTDT by Anonymous Coward · · Score: 0

      Yeah, some guys want a woman while others want a hole. Those that want just a hole either die alone or find out that there are other holes without women attached.

    54. Re:BTDT by bluefoxlucid · · Score: 1

      I don't think I could write in Java without having an understanding of the APIs. I tend to write way better in C than my peers, but that's because I'm a fan of extreme code reuse and hierarchical problem solving, as well as unit testing and the like. As such, I'm used to programs that take 5 megs of RAM to do what something written in C++, Java, or C# takes 500 megs of RAM to do.

      Too bad my computer limps around with 4 gigs of RAM, loading my desktop in 400+ megs off a clean install. I remember when I ran on 64 megs, and that was a lot...

    55. Re:BTDT by Steve+Max · · Score: 1

      Fortran is one of the most used languages in the world and the most used for HPC, because it's easy to code and fast. It was only on the last few years that C compilers started to compete against the best Fortran compilers out there, and so we have some HPC tools on C/C++. People tend to use the best tool for the job among those they know how to use, or learn a new one if the effort is worth it; and in some cases, "old" languages are the best tool (or learning new languages for a small improvement isn't worth it)

    56. 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.

    57. Re:BTDT by I'm+not+really+here · · Score: 1

      Unfortunately I only come here from an RSS feed, so that setting is completely useless to me. Come on Slashdot... lets get a feed for each editor so we can pick and choose even in RSS!

      --
      Before commenting on the Bible, please read it first
    58. Re:BTDT by Sancho · · Score: 1

      TFS is very confusing because it links to two seemingly different examples of how to create a tiny executables on Linux. There's the MIT one by Jessica McKellar (second link in the summary) which is an example of a Hello World. Then there's the third link in the summary which appears to be by Brian Raiter. This third link is just creating the smallest ELF program possible--it just returns the number 42 to the OS without printing anything.

    59. 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.

    60. Re:BTDT by Anonymous Coward · · Score: 0

      Slashdot used to review piers all the time. Unfortunately this is news for nerds and eventually it was branched off into a fishing site.

    61. Re:BTDT by argent · · Score: 1

      Fortran - 1957
      Lisp - 1958
      Algol - 1958
      Simula - 1967
      Smalltalk - 1969
      C - 1972
      C++ - 1983

    62. Re:BTDT by hitmark · · Score: 1

      i think linux have a similar behavior when it comes to libs at least, with the end result that people coming over from windows and looks at the ram usage stats thinks linux is more heavy on the ram then it really is. This then comboes with windows habit of keeping some ram free for future use, and they freak out when they see linux make use of all ram all the time...

      --
      comment first, facts later. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm
    63. Re:BTDT by argent · · Score: 1

      Actually, now I think of it, UNIX used the ability of the PDP-11 to recover from a page fault to dynamically extend the stack by trapping stack probes in function preambles, adjusting the stack break, and resuming the interrupted instruction. This caused some pain in some of the early ports to CPUs that couldn't recover from a page fault in all cases. I seem to recall reading about a 68000 port using a specific instruction that happened to be recoverable for stack probes...

    64. Re:BTDT by Narcocide · · Score: 1

      ... I still thought it was nice of her to go through the trouble of explaining step-by-step how to do it though.

    65. Re:BTDT by tomhudson · · Score: 1

      Sure, but this one from muppetlabs is much more complete, better-written, predates it by more than a decade (July 1999), etc. You can combine that with the overview and the other examples for a much better understanding.

    66. Re:BTDT by argent · · Score: 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.

      I remember the first time that happened automatically, when we upgraded from version 6 to version 7.

      fd0, fd1, and fd2 are opened by your parent process. stdin, stdout, and stderr may or may not be created from these by crt0.o... in Version 6 UNIX stdio was pulled in with -lS and initialized the first time you called a stdio routine. If you didn't use stdio and just used the default C runtime you got old unbuffered variants that worked directly on file descriptors. You had to be careful using stdio on Version 6 because this was before the bourne shell... shell scripts ran by reading directly from fd0, and "if", "while" and "goto" were programs that seeked around on stdin looking for lines beginning with a ":". Throw a stdio program in the wrong place and it could eat the whole script after it.

    67. Re:BTDT by NotBornYesterday · · Score: 1

      WHOOOOOOSH!

      --
      I prefer rogues to imbeciles because they sometimes take a rest.
    68. Re:BTDT by QuietObserver · · Score: 1

      No offense, but how big? I wrote "Hello World" for the Commodore 64 (6510, a 6502 derivative) in a miniassembler today in five minutes, and it maxed out at 38 bytes (this includes the "print" function and the text).

      Here's the code; the labels are addresses because miniassemblers only use addresses, not labels (and yes, I did have to insert the text in hexadecimal, but I'm providing the text to simplify):
      C000:
            LDA #$19
            LDY #$C0
            STA $FB
            STY $FC
            LDY #$00
      C00A:
            LDY ($FB),Y
            BEQ $C018
            JSR $FFD2
            INY
            BNE $C00A
            INC $FC
            BNE $C00A
      C018:
            RTS
      C019:
      DB "HELLO WORLD!", $00

    69. Re:BTDT by QuietObserver · · Score: 1

      Sorry about replying to myself; made the code 39 bytes by adding a comma after 'Hello.' Also, I could have reduced the code to only 35 bytes by making the function only support 256 bytes of string (removing the INC $FC and its corresponding BNE $C00A; the BNE uses only two bytes, since one is an eight bit offset to PC).

    70. Re:BTDT by argent · · Score: 1

      After 30 years, who remembers?

      If you give up the requirement of making it a complete UNIX executables and making UNIX system calls, I bet I could come up with a version for an IBM 1620 or some other old iron where "punch" was a native instruction that's smaller than that.

    71. Re:BTDT by QuietObserver · · Score: 1

      Perhaps, but my code includes the system calls (JSR $FFD2 calls CHROUT from the Commodore 64's KERNEL; it's a jump table address).

    72. Re:BTDT by BitZtream · · Score: 1

      Yea, and add a slice of 'no shit, ASM can do it in less than anything else', since you know, thats how EVERYTHING ENDS UP anyway.

      Taco, seriously, remove kdawson and timithoy's access to post stories to the front page.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    73. Re:BTDT by BitZtream · · Score: 0, Flamebait

      Compiling code in your basement doesn't mean you know C.

      Googling random shit on the Internet and getting something to compile doesn't mean you know the language.

      Backing a car out of your drive doesn't mean you can actually drive.

      I'm sorry to burst the bubble you and most of the 'geeks' on the Internet seem to have, but you really don't have a clue if you didn't know this.

      This is something that comes up VERY FREAKING EARLY ON in the education process of learning to program. Given enough time you should be able to infer it on your own.

      My guess is that you think using visual studio wizards, cut and paste, and some primitive ability to cobble something together that compiles and runs makes you believe you know C. This is about the same as people who think because they can make a form in VB that they are programmers and can make production quality software.

      I realize that not knowing much about being a programmer you think that its acceptable to not know something like this because you are learning. The thing is, if you don't know this you really have not put any effort into understanding whats going on when you compile a program. The problem is, for those of us who know what we're doing, people like you who THINK you have a clue, but really have no understanding what so ever of whats going on are EXTREMELY frustrating to us. Your the kind of people that post on the dev mailing lists for something like libxml asking for example code for your specific situation by stating something like 'I'm trying to read xml from a file and manipulate it, can someone give me everything I need to do that ... as an example, but working for me!' to which if you get a response, will be one of two things 'learn to code' or 'read the docs'.

      You'll find doctors have the same sort of reaction when you tell them you've been playing doctor for yourself for years with things you saw on the Internet. Those of us with a clue tend to get annoyed by people with no clue who think because they've been doing it for years (most likely wrongly) they get to be treated like they have a clue.

      Make a statement that makes it clear you don't have a clue when you're hanging out with a bunch of people that DO have a clue tends to get you treated like someone who shouldn't be participating in the conversation.

      To programmers, the statement made here is roughly like this:

      Motivating a car using a gasoline engine or electric motor is a lot easier than pushing it with human.

      Thats the level of statement made here. If someone walked up to you and told you that, you'd say 'uhm ... no shit sherlock, if you didn't know that you don't need to drive a car'

      While that might be useful for a caveman to know, its not useful for anyone who should be driving a car, and anyone who does drive a car, that isn't aware of the facts of the statement shouldn't be driving a car.

      Don't tell us about how long you've been using GCC when you have absolutely no idea how it works, the length of time is irrelevant if you don't bother to educate yourself on how it works.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    74. Re:BTDT by kmoser · · Score: 1

      Yeah, but she hates men. That's hot.

    75. Re:BTDT by argent · · Score: 1

      I wouldn't call an 8-bit monitor a kernel, but if I were to do one I'd take advantage of the fact that JSR STROUT on the Apple II outputs a whole string. Then I'd use JMP STROUT so I didn't have to include my own RTS. Bet you could get that under 20 bytes.

    76. Re:BTDT by Anonymous Coward · · Score: 0

      Nope, she gets a hello world down to 1329 bytes, the bloke who did the 45 byte one was Brian Raiter.

    77. Re:BTDT by Anonymous Coward · · Score: 0

      Two articles here - one by a woman (the main article) and one that goes deeper into ELF by a man (older article linked in the the main article).

    78. Re:BTDT by palegray.net · · Score: 1

      Kinda my point... it seems there's been a rash of failure to RTFS recently, in addition to the usual failure to RTFA.

    79. Re:BTDT by palegray.net · · Score: 1

      Patronizing? What are you talking about? I was correcting the poster who indicated her gender as being male. Quite the reverse of your misinterpretation of my point, I was lending credence to the oft-ignored fact that there are some brilliant women in computer science. I considered her article one of the best things I've read in years, regardless of gender. What are you smoking?

    80. Re:BTDT by palegray.net · · Score: 1

      There's nothing confusing here if you actually read the full article by Jessica.

    81. Re:BTDT by palegray.net · · Score: 1

      No. Jessica wrote the full article on stripping "hello world" down to the minimum possible byte count. Please read it again.

    82. Re:BTDT by palegray.net · · Score: 1

      Considering the average Slashdotter and the men she's surrounded by at MIT every day, I'm really not surprised.

    83. Re:BTDT by Sancho · · Score: 1

      I don't see how that follows, though while searching to see if I missed a link to the muppetlabs page, I did note that someone mentions it in the comments.

      The summary is still unnecessarily confusing, as it conflates the two pages.

    84. Re:BTDT by clemdoc · · Score: 1

      Aren't we all anxiously waiting for the time when it will no longer be usual to RTFC before hitting 'Reply to This'?

    85. Re:BTDT by Anonymous Coward · · Score: 0

      > Yeah, but she hates men. That's hot.

      You may think so, but I think there is a double standard at work here.

      If a man in a similar position at MIT posted a pic of himself with a laptop displaying the message "I HATE WOMEN," he'd be crucified for it, and rightly so. Nobody would think it was "cute" or "hot."

    86. Re:BTDT by jlehtira · · Score: 1

      My guess is that you think using visual studio wizards, cut and paste, and some primitive ability to cobble something together that compiles and runs makes you believe you know C.

      When I wrote assembly code for that motorola dsp chip, there was no "startup code" or library. Same thing for intel assembly, although then I was mostly playing around on a 386. Then there's a flavor of risc assembly and PIC chips - four different assembly codes I've written stuff with. In all of these I'd write code, and that code would directly go to wherever execution would start.

      Okay, so I knew about ELF headers, but not about _start(), and thought that C probably does something similar to assemblers. Why not? Okay, that's probably a long story. Also, that story would not matter at all in practice, unless I finally decided to write a 4kb demo, something I've wanted to do for over ten years.

      I realize that not knowing much about being a programmer you think that its acceptable to not know something like this because you are learning. The thing is, if you don't know this you really have not put any effort into understanding whats going on when you compile a program. The problem is, for those of us who know what we're doing, people like you who THINK you have a clue, but really have no understanding what so ever of whats going on are EXTREMELY frustrating to us.

      I think it's acceptable because there's just too much to know in computers, for any one person to ever grasp everything at every level. I made my choices and focused on electric engineering - I can build logical ports from electric components, I can design a simple processor, I can optimize a scientific Fortran code for a supercomputer. These skills are useful and adequate for many tasks, although certainly not all!

      Your the kind of people that post on the dev mailing lists for something like libxml asking for example code for your specific situation by stating something like 'I'm trying to read xml from a file...

      Hey, I have no problem reading an API, and I can figure out stuff by thinking and trying things ;).

  2. Hello World by Anonymous Coward · · Score: 0

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

    1. 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
    2. Re:Hello World by Anonymous Coward · · Score: 0

      yeah, right. i heard he invented the internet too.

    3. 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!
    4. Re:Hello World by Anonymous Coward · · Score: 1, 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.

      His was a variant that was tradmarkable. "iHello iWorld". Sadly it being an executable file means it to won't run on an iphone.

    5. Re:Hello World by Ihmhi · · Score: 1

      And a trademark on "iGreet".

    6. Re:Hello World by Wovel · · Score: 1

      You must be thinking of an android phone. You can run any executable you want on an iphone. In Android you can run anything you want in a JVM on your phone. (Personally I don't want to run anything at all in a JVM on my phone that I don't absolutely have to, whats next flash!)

    7. Re:Hello World by GigaplexNZ · · Score: 1

      Android is an open source OS based on Linux that can run natively compiled applications. The official SDK however is Java based, but that doesn't make it impossible to run C apps.

    8. Re:Hello World by GigaplexNZ · · Score: 1

      You heard wrong. That accomplishment belongs to Al Gore.

    9. Re:Hello World by Anonymous Coward · · Score: 0

      Welcome to the iNternet!

    10. Re:Hello World by SharpFang · · Score: 1

      The iWorld in question, being a more lean and user-friendly variant of the World, created in only 4 days (compared to the original 6+1 of testing). Unfortunately, iWorld can have only one of gravity, electromagnetic, strong or weak force working at the same time. People living there say it doesn't bother them though.

      --
      45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
    11. Re:Hello World by mdwh2 · · Score: 1

      By that pedantry, you might as well say "You can't run exes on an Iphone, you can only run exes on the OS that runs on the Iphone".

      You can run any executable you want on an iphone.

      If you go to the bother of having to jailbreak it. It "Just Works".

  3. 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 Anonymous Coward · · Score: 0

      I was told there would be "Hello World", WTF?

    2. Re:Missing the point by Idiomatick · · Score: 1

      42 is short for hello world apparently.

    3. 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.

    4. Re:Missing the point by Anonymous Coward · · Score: 0

      True, and she misses the perfect size by three bytes.

      But for just 37 bytes more, you can have hello world: http://pastebin.com/bnR8P2Hs

    5. Re:Missing the point by Anonymous Coward · · Score: 0

      She could have used a system call to the kernel with only a few more bytes.

    6. Re:Missing the point by Anonymous Coward · · Score: 0

      looks like a bunch of pirates;
      there is no more fun at all

    7. Re:Missing the point by klui · · Score: 1

      I was kinda hoping the file size dropped to 42 as well.

    8. Re:Missing the point by kevingolding2001 · · Score: 1

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

      I suspect that this is the subject of the 'to be continued' article next week.
      Yes I was a bit disappointed, but I eagerly await the "what will happen next" conclusion.

    9. Re:Missing the point by PhilHibbs · · Score: 1

      42 isn't the answer to every possible question, it's only the answer to "what do you get when you multiply six by nine". It may be the answer to the only question that has any fundamental relevance in this universe, but I'm sure there are other universes that were designed to answer other questions. Some of them might have got it right.

    10. 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?
    11. Re:Missing the point by snspdaarf · · Score: 1

      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!".

      Uh, wouldn't that be the Ultimate Improbability Compiler?

      --
      Why, without your clothes, you're naked, Miss Dudley!
    12. Re:Missing the point by Anonymous Coward · · Score: 1, Funny

      I once tried to make the elf my bitch. The GM (and oddly other players weren't too amused.

    13. Re:Missing the point by shutdown+-p+now · · Score: 1

      Not just that, but writing startup & shutdown code in assembly also sidesteps the "C" part of the program.

    14. Re:Missing the point by ncc74656 · · Score: 1
      ]call-151
      *!
      !300:ldy #0
      !:lda 30e,y
      !:beq 30d
      !:jsr fded
      !:iny
      !:bne 302
      !:rts
      !
      *30e:c8 e5 ec ec ef ac a0 f7 ef f2 ec e4 00
      *300g
      Hello, world
      *

      (OK, so it still relies on a Monitor routine to do character output, but if you replaced "jsr fded" with something like "sta 400,y", you'd blast it straight to the upper-left corner of the screen and use no outside routines at all.)

      --
      20 January 2017: the End of an Error.
    15. Re:Missing the point by Anonymous Coward · · Score: 0

      But... 6 * 9 = 54 ????

    16. Re:Missing the point by Anonymous Coward · · Score: 0

      Indeed. For some context, I've made it a long-time habit not to include glibc on Windows when writing dlls (because of the size and because of conflicts I've experienced). Now if you would write such a hello world on Win32, you'd probably call MessageBox in User32, using that library to do all the heavy lifting. Now, look at the code in the article. Sure, it contains a syscall rather than a normal call, but you can see that it does exactly the same thing. It provides the string and passes it to the function that does the actual work, in effect still using a library provided by the operating system.
      If you'd want to do a purer hello world, you'd do something with an eeprom, a microcontroller, and a simple controllerless printer. We've done stuff like that (but controlling instruments, not a printer of course) in a physics practicum once.

    17. Re:Missing the point by Anonymous Coward · · Score: 0

      Bush atacked the wrong country and destroyed the economy, Obama got left with the mess.

      There, fixed that for you Mr Beck.

  4. 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 Anonymous Coward · · Score: 1, Insightful

      Actually the primary reason your system is so slow, is because your using 1960's technology for storing your data. It is perfectly normal... and expected that your computer will need to store and retrieve information to load Windows / Programs / Web browser's etc.. using an old slow Hard Drive is the primary reason systems are so slow nowadays. As it starts swapping data to your 1960's technology (aka Hard Drive) the whole system slows to a crawl while your super fast memory and super fast CPU waits forever for read/write heads just to move around.

      You could take an old P4 with 2GB with Win7 and slap an SSD Drive into it, and it will run circles around the top of the line corei7 systems in normal day to day home and office tasks.

      I can see your point about memory waste though, years back as part of a school project I had to create a "Hello world" visual basic program, and I was flabbergasted at how long it took to open and how much memory it took, for such a simple task.

    5. 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.

    6. Re:So what? by confused+one · · Score: 1

      That's because you used Visual Basic, which pulls in its own libraries (and maybe a vm) on top of the system libraries. Visual Basic is the definition of bloat. I know, I use it every day. It makes the "Hello World" program built with gcc, which pulls in libc by default, look like a minimalist dream by comparison.

    7. Re:So what? by beelsebob · · Score: 1

      Alternatively, thinking like that really has nothing to do with it. Constant overheads disappear into insignificance compared to bad algorithms.

    8. Re:So what? by julesh · · Score: 1

      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.

      Which will only happen if you're actually using those 11k, and hence they aren't wasted...

    9. Re:So what? by Setsquare · · Score: 1

      I get 517K for a static link of a hello world executable. 5.8K for dynamic. That really is super pathetic. (I'm on linux running gcc 4.4.3-3, the static file was stripped)

    10. Re:So what? by GigaplexNZ · · Score: 1

      As it starts swapping data to your 1960's technology (aka Hard Drive) the whole system slows to a crawl while your super fast memory and super fast CPU waits forever for read/write heads just to move around.

      You keep believing that the memory is super fast. CPUs are getting a heck of a lot faster rather quickly, but the memory latency isn't decreasing much. This means that it takes more and more CPU cycles just to fetch data from RAM.

    11. Re:So what? by GigaplexNZ · · Score: 1

      Or abstraction on top of abstraction on top of abstraction. Garbage collectors and JIT compilers etc are all well and good until you realise how much overhead they add to certain tasks.

    12. Re:So what? by Xest · · Score: 1

      Alternatively, maybe thinking like that is exactly why we have any amount of complex software in the first place.

      If we spent weeks quibbling over saving a few kilobytes, then we'd never actually get any decent modern software written at all.

      I just searched for *.exe on my laptop, there are 4955. Every executable on the hard drive having 11k extra, equates to around 53mb or so of extra data. On a 160gb hard drive, that's literally fuck all. It might be an pain on a 1gb hard drive, it may be an inconvenience on a 10gb hard drive, but on a 20gb or more hard drive, really, who cares? Even if you somehow managed to run every executable on your system at once on a 4gb RAM machine 60mb out of that is hardly a big deal.

      In reality, I actually only have 80 processes running though, which is 880k, a fairly trivial amount of data (i.e. less than half a percent) out of even 256mb of RAM, let alone out of 1gb, 2gb, 4gb, or 8gb as modern machines have.

      This meme about how applications are bloated and so forth because they're not handcrafted in assembly anymore really needs to die, it's so utterly out of date it makes no sense on modern PCs- it might matter on embedded systems and such but that's not what we're talking about here. Sometimes people have this nostalgic get off my lawn view of "When I was a lad, I had to save every kilobyte I could whilst walking 50 miles uphill in 20ft of snow to school each morning", that's nice, really, but you also didn't have software that had half the features, or games that had even close to the visual effects of even the low end software around nowadays. Even my phone is more impressive than my PC was a mere 10 years ago- and handcrafted assembly barely even mattered for the vast majority of apps then.

      I'm not saying there isn't still bloated software out there, of course there is, it's a fair comment- but quibbling over 11k? really? Even if it's 11k that takes a programmer only 15 minutes to shave off, it's still not cost effective for anyone to have a programmer doing that in the vast majority of circumstances.

      If every executable on the hard drive has 11k extra data because everyone thought it was insignificant, then well, yeah, they were right actually.

    13. 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.

    14. Re:So what? by beelsebob · · Score: 1

      Not using abstraction when you program is all well and good until you realise how much less stable, maintainable and fast to write it makes all tasks ;).

    15. Re:So what? by GigaplexNZ · · Score: 1

      I didn't suggest using no abstraction, just pointing out that overuse of abstraction yields minimal gain in productivity and introduces more overhead than necessary. If you are happy to pay that overhead, that's fine, it just happens to be another cost that dwarfs the constant overhead in addition to bad algorithms.

    16. Re:So what? by CarbonShell · · Score: 1

      I agree to a limit, but developers really have become wasteful as ram became more freely available and even moreso with the introduction of garbage collectors in languages.
      You can often tell someone who comes from a more '(near-the-)boiler-plate' side of development then others, as they do tend to write more (possibly unneeded) optimised code and (possibly also unneeded) extra cleaning up.
      Though I must say, even if it is sometimes unneeded, if I see such code I tend to trust the code (and thus the developer) more, unless I see other signs that the developer might have just switched the language but not adapted to it (I often see it in developers that switch between C/VB to Java).

    17. Re:So what? by mdwh2 · · Score: 1

      You prefer so-called "optimised" code when it makes no difference to performance? And even when that may lead to code that's harder to read, maintain, port and so on?

    18. Re:So what? by EkriirkE · · Score: 1

      ...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...

      I was doing all of these on my 386 4MB machine, windows 3.1 and aol+realplayer (I know, I know...)
      Around Y2K I started seeing the bloat; programs that would tell you your local IP address at 1MB, where if assembled natively could go to 1KB (512 stub, 512 data/code), Installers that no longer fit on floppy disks for new versions of programs that provided nothing new compared to older, slimmer (exe) versions.
      Hell, I had no problem multitasking VisualStudio6, ICQ, Yahoo, Netscape on my 486/66, upgraded to 64MB RAM + 1GB HD. Now I can barely run firefox alone on 4GB ofRAM.
      The only time I had to kill things was when I went into photoshop or premiere which heavily cached in RAM.

      --
      from 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
      to 45 2F 6E 40 3C DF 10 71 4E 41 DF AA 25 7D 31 3F
    19. Re:So what? by Yosho · · Score: 1

      I was doing all of these on my 386 4MB machine, windows 3.1 and aol+realplayer (I know, I know...)

      No you weren't. A single uncompressed frame of 1080p video is slightly under 6 MB in size. You couldn't even fit that into your RAM, let alone replace it 29.97 times per second while your computer is running other tasks in the background. I'd believe that maybe you were watching 160x120 RM videos at 10 frames per second that had compression artifacts the size of my thumb.

      Now I can barely run firefox alone on 4GB ofRAM.

      Which is, of course, extreme hyperbole. I've got an open Firefox process that's been running for at least a day and has had over a dozen tabs open and it's at around 160 MB. The machine I'm on has 4 GB of RAM, about 2 GB of which is in use, and I've got Firefox, Opera, Chrome (doing web development at the moment), Eclipse, a dozen terminals, two remote desktop displays, Pidgin, an e-mail client, a SQL client, a music player, and our VCS program open. I suppose I've also got a local Apache HTTP server running. I can't remember the last time I hit the swap disk.

      If Visual Studio 6, ICQ, and Netscape all did everything that your current programs do, why aren't you still using them?

      --
      Karma: Terrifying (mostly affected by atrocities you've committed)
    20. Re:So what? by noidentity · · Score: 1
      Furthermore, any program which does much is going to use most of the routines in that 11K that's always linked in.

      Still, growing up with the Mac compilers of the 1990s where stripping unused routines out of the executable was a standard feature, I'm amazed that many compilers even today don't do that. If I define 20 functions in a source file and only call one, and it doesn't call any of the others either, why the hell does the linker link everything else in? I've written several toy assemblers over the years and they all stripped out unused routines (you'd mark the boundary between each routine so the linker knew). It's very useful there because size does matter when writing in assembler, and you might want to include a general utilities library without having to manually figure out which routines you actually call.

    21. Re:So what? by Pinchiukas · · Score: 1

      It would be nice if we could use the same libc to write programs for them.

    22. Re:So what? by Anonymous Coward · · Score: 0

      We're talking about RAM...process space...not hard disk storage.

    23. Re:So what? by Xest · · Score: 1

      Yes, and I was talking about both which is quite obvious to anyone who bothered to read my post.

      Or were you not aware that an image of an executable on disk gets copied into RAM at runtime so 11kb extra on disk is still just 11kb extra in process space?

      See my point about 80 processes running at once, with 11kb extra would still only be an extra 880kb of RAM used if it was across all processes- i.e. not enough to matter to anyone using a system less than about 10 years old.

    24. Re:So what? by mcfedr · · Score: 1

      it that 11k is truly useless it will never make it as far as the cache...

    25. Re:So what? by Reservoir+Penguin · · Score: 1

      Right, and thanks to that half the reason many use Firefox is the extensions that DISABLE or severely limit JS and other crap that wants to load itself and render in your browser.

      --
      US-UK-Israel: The real Axis of Evil
  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 sootman · · Score: 1

      Hey, be nice, it's (evidently) the first slow news day in over 10 years! :-)

      --
      Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
    3. Re:Old news is VERY OLD by Anonymous Coward · · Score: 0

      ... I read this about 10 years ago...

    4. 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.

    5. Re:Old news is VERY OLD by capebretonsux · · Score: 1

      "All this has happened before, and all this will happen again."

    6. Re:Old news is VERY OLD by coaxial · · Score: 1

      Perhaps, but everything old is new again. Would you have thought back in 1999 that we would be sending messages to each other using a proprietary centralized system with 140 statically allocated character arrays? I don't think so.

    7. 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
    8. Re:Old news is VERY OLD by siride · · Score: 1

      And this one is actually interesting, unlike hers, which simply cuts out libc (boring). This one overlays the ELF header with the program code itself, which I find to be rather clever. In fact, it's better than the 29 byte DOS COM executable because COM files don't have headers and so don't have to deal with that problem.

    9. Re:Old news is VERY OLD by Anonymous Coward · · Score: 1, Funny

      That's just the Lords of Cobol being pissed that the Lords of Fortran did it first.

    10. Re:Old news is VERY OLD by Anonymous Coward · · Score: 0

      I'm confused

      File hello.c saved
      me@mycomputer:~$ gcc -O2 -Wall hello.c -o hello
      me@mycomputer:~$ ls -l hello
      -rwxr-xr-x 1 pepsi users 6222 2010-03-17 03:19 hello*
      me@mycomputer:~$ hello
      hello world
      me@mycomputer:~$ gcc -s -O2 -Wall hello.c -o hello
      me@mycomputer:~$ ls -l hello
      -rwxr-xr-x 1 pepsi users 2748 2010-03-17 03:20 hello*
      me@mycomputer:~$ hello
      hello world
      me@mycomputer:~$ gcc -v
      Reading specs from /usr/lib/gcc/i486-slackware-linux/4.2.4/specs
      Target: i486-slackware-linux
      Configured with: ../gcc-4.2.4/configure --prefix=/usr --enable-shared --enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --with-arch=i486 --target=i486-slackware-linux --host=i486-slackware-linux
      Thread model: posix
      gcc version 4.2.4

    11. Re:Old news is VERY OLD by ktappe · · Score: 1

      gcc version 4.2.4

      Ah. I get: gcc version 4.2.1 (Apple Inc. build 5646) (dot 1)

      Something else Apple chose to eliminate when they assimilated Unix?

      --
      "We can categorically state we have not released man-eating badgers into the area." - UK military spokesman, July 2007
    12. Re:Old news is VERY OLD by klui · · Score: 1

      The article was last updated in 2009 http://www.muppetlabs.com/~breadbox/software/tiny/teensyps.html. Check out the link at the bottom.

    13. 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.
    14. Re:Old news is VERY OLD by Anonymous Coward · · Score: 0

      Reddit should be renamed to Regurgit.

    15. Re:Old news is VERY OLD by Rogerborg · · Score: 1

      Steady on - it's the first time in years that kdawson has posted anything that's not a shill for snake oil salesmen. Let's encourage him in his new-found appreciated of actual tech news, even if it's old news.

      --
      If you were blocking sigs, you wouldn't have to read this.
    16. Re:Old news is VERY OLD by Anonymous Coward · · Score: 0

      This is beyond old. I think back in the mid/late '80's, I was working with commercial compilers that could easily optimize printf's to eliminate the need for all the extra formatting libraries that a simple string print didn't need.

      Maybe it's an indication that I no longer feel that coding in assembler is worth the expense, but when I read "simpler hello world", I thought that the "simpler" was some sort of magic C code that made the actual program text simpler,

    17. Re:Old news is VERY OLD by Aidtopia · · Score: 1

      And that link was the follow-up article. Matt Pietrek's first column on this topic was in MSJ in 1996.

  6. Where's the I/O? by Anonymous Coward · · Score: 0

    Maybe it wasn't her fault, but the /. summary promised our little greeting. I expected a trip down memory lane to the old "DOS" interrupt INT 21H. But not even.

    FAIL

  7. 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 Short+Circuit · · Score: 1

      So now the average Slashdotter might know what the "bloat" you're talking about is for: Making it so that the programmer doesn't require as much in-depth knowledge of his platform, or have to do as much of the mundane work himself.

      (At least, the average article-reading Slashdotter. Needed to clarify that before someone else points out the joke...)

    3. 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
    4. 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.

    5. Re:Nice but? by klui · · Score: 1

      I've written about this on slashdot on a couple of occasions. Take for example the latest version of iTunes and Quicktime on Windows. There is a lot of functionality I don't need. So instead of downloading 100MB, I uninstalled it and downloaded foobar 2000 at 3MB + some other components that totaling around 6MB.

    6. Re:Nice but? by GigaplexNZ · · Score: 1

      Of course competent programmers do not need trash collection, but it sure makes life easier, and can cut down on programming hours.

      As someone coming from C++ and is just starting to port over to C#, I actually find the GC more of a hindrance than a help a lot of the time. Sure, being able to new something without having to think about when to delete later may seem useful at first, but I spend more time fighting against the GC trying to convince it to clean up and avoid fragmentation in the Large Object Heap, handle COM reference counts safely without waiting for the GC to clean up C++ side objects (it proxies through the RCW which holds a single reference until someone forcibly releases it in an unsafe manner or waits for the GC to clear the RCW) or just be able to throw away a collection and create a new one without worrying about allocation failures as a result of the GC not being aggressive enough. A smart pointer that deletes when going out of scope or reference count going to zero isn't that difficult to learn in C++ and gives more control when you want to try to do something fancy.

    7. Re:Nice but? by anss123 · · Score: 1

      The other day I downloaded a mouse driver for my shiny new mouse. I remember a time when a big mouse driver that used 25KB of memory was big, now they need 25MB for the compressed download and about the same amount of RAM.

      Imagine if these drivers existed when Windows95 was new. "System requirements: Win95 PC with 25MB RAM and 100MB free space"... WUT NO WEY

    8. Re:Nice but? by Anonymous Coward · · Score: 0

      Or you can write it in java, or god forbid, C#, and still pretend that it is not only as efficient (or maybe more!, you know, that JIT thing...) as the native version, but also more portable.

      This article is NOT about saving a few bytes. It's about knowing your stuff.

    9. Re:Nice but? by jez9999 · · Score: 1

      Come on, that's below the belt.

      Gates isn't THAT incompetent.

    10. Re:Nice but? by vegiVamp · · Score: 1

      I take note that you don't specify coding to deliver a *good* product at a reasonable cost.

      --
      What a depressingly stupid machine.
    11. Re:Nice but? by TheTurtlesMoves · · Score: 1

      GC is great if you don't have anything outside the GC that you need to worry about. When you go multi threaded its a blessing, most C++ i worked hacked reference counting to deal with the "some thread could be using it" problem. However I always thought that with C# it would be tricky including "legacy" COM stuff.

      New generational GC that uses copy rather than mark and sweep, cuts down on fragmentation quite a bit.

      --
      The Grey Goo disaster happened 3 billion years ago. This rock is covered in self replicating machines!
    12. Re:Nice but? by steelfood · · Score: 1

      But complaining that we unnecessary library code is sometimes included does not really solve any problems.

      Yeah, those insensitive clods!

      --
      "If a nation expects to be ignorant and free in a state of civilization, it expects what never was and never will be."
    13. Re:Nice but? by Sycraft-fu · · Score: 1

      That's my point though, we've got the space now so why not? Also, part of the reason they may be so large is they provide more functionality. Your computer likely had a mouse driver already. In fact it has a single set of drivers for USB mice, keyboards, joysticks and so on in the form of the HID drivers. Maybe 100k between the couple of sys files they use. What your drivers likley did was add a lot of functionality.

      For example on my mouse, the driver enables me to graphically control just about any aspect. I can remap any button to any function I like, including macros, I can modify acceleration details, including setting multiple levels of sensitivity to be changed by buttons on the mouse, I can have different profiles to auto load for apps and so on. That's what takes up all the space. The actual driver itself is likely pretty small. It's all the added functionality that I get and controls for that functionality.

      I like that though, and as I said, I don't lack for space so why not?

  8. BASICally she did this by Anonymous Coward · · Score: 0

    Start with: 10 PRINT "Hello World" 20 END The Went to: 10 PRI "Hello World" Then finally came down to: 10?"Hello World"

  9. 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 Dynetrekk · · Score: 1
      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?

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

      Commodore BASIC:

      ?42

    3. 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,!

    4. Re:I can code that app in... by i_ate_god · · Score: 1

      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?

      --
      I'm god, but it's a bit of a drag really...
    5. Re:I can code that app in... by Anonymous Coward · · Score: 0

      Not just that, your shell script requires all the bytes of an interpreter to run it. Nice try, though.

    6. 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?

    7. Re:I can code that app in... by Anonymous Coward · · Score: 0

      On a similar note, how big is the operating system you're running python/bash/C/whatever on?

    8. Re:I can code that app in... by Anonymous Coward · · Score: 0

      How big is SH?

    9. Re:I can code that app in... by Anonymous Coward · · Score: 0

      And your interpreter can fit in 24 bytes? That's truly impressive.

    10. Re:I can code that app in... by quietwalker · · Score: 1

      Back in college, one of our CE exams required us to build a small system to process incoming data at a certain rate. Most sat down and banged out a simplified assembly language, snapped all the hardware together required to implement it, wrote a little asm program to feed the data and away they went, counting clock cycles and optimizing to ensure they met the requirements.

      One of my friends realized there was no need for all that, and created a language with a single instruction; "go".

      Semantically then, this would have been a one-bit program. Though he might have used a half-byte for instructions. Room to expand, you know.

    11. 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.

    12. 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.

    13. Re:I can code that app in... by Anonymous Coward · · Score: 0

      As a bonus, it fits in a twitter post! http://www.sics.se/~adam/twip.html

    14. Re:I can code that app in... by Anonymous Coward · · Score: 0

      Your python script isn't setting the exit code to 42, as the shell script does.

    15. Re:I can code that app in... by Anonymous Coward · · Score: 0

      wc -c /bin/sh
        1346656

    16. Re:I can code that app in... by Anonymous Coward · · Score: 0

      I modified your lengthy script and got 17 bytes.

      I changed two things:

      #!/bin/sh
      echo 42

  10. Thanks! by Anonymous Coward · · Score: 0

    Nice to see someone actually caring about removing bloat from software after VB, Java, .NET and the
    corporate culture behind them literally destroyed any incentive in producing optimized code, nearly
    killing the demand for skilled programmers capable of writing such code.

    Also, for those working with smaller systems this is a godsend.

    1. Re:Thanks! by Anonymous Coward · · Score: 0

      Except for the fact that most of the bloated and slow programmers in Windows and Loonix are written in either C and C++.

    2. Re:Thanks! by GigaplexNZ · · Score: 1

      Except for the fact that most of the bloated and slow programmers in Windows and Loonix are written in either C and C++.

      A human written in either C or C++?

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

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

    1. Re:Umm, but by rotide · · Score: 1

      The program output was '42'. If you had bothered to click the link and verify your claim, which you obviously didn't, you would have seen the output.

    2. Re:Umm, but by Anonymous Coward · · Score: 0

      Hmm

    3. 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".

    4. Re:Umm, but by Anonymous Coward · · Score: 0

      The "42" isn't output, it's the process exit code that a parent C app can recover using the easy-to-remember macros WIFEXITED and WIFEXITSTATUS.

      "Wait a minute. This isn't an argument... it's just negation!"
      - Eric Idle

    5. Re:Umm, but by ralphdaugherty · · Score: 1

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

            Maybe they should call it Hello 42, I can see you with a debugger?

    6. Re:Umm, but by Kingrames · · Score: 1

      It's quantum output, you fool! By viewing it, you've changed it!

      --
      If you can read this, I forgot to post anonymously.
    7. Re:Umm, but by The+Clockwork+Troll · · Score: 1

      The answer to that question is 42.

      --

      There are no karma whores, only moderation johns
    8. Re:Umm, but by The+Clockwork+Troll · · Score: 1

      When you symlink /dev/null to Soviet Russia.

      --

      There are no karma whores, only moderation johns
    9. Re:Umm, but by ArsenneLupin · · Score: 1

      The program output was '42'.

      No, that was not the output, that was the exit status.

      However, for just 37 bytes more, you can have a real hello world program: http://pastebin.com/bnR8P2Hs

    10. Re:Umm, but by blind+biker · · Score: 1

      It outputs 42. It helps to read TFA sometimes.

      --
      "The agriculture ministry is not in charge of Gundam" - Japanese ministry official.
  12. 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?

  13. 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.
    1. Re:If it's so simple, by Anonymous Coward · · Score: 0

      It probably doesn't pass the lameness filter...

    2. Re:If it's so simple, by TangoMargarine · · Score: 1

      Even if Slashdot *is* News for Nerds, not everyone can read uncommented assembly.

      --
      Unity? Screw that: XFCE. Slashdot Beta? Screw that: SoylentNews. Australis? Screw that: Pale Moon. UX developers DIAF
  14. 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. =)

  15. 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.
  16. 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 hudsucker · · Score: 1

      It's also used to dummy out call in a load module. That is, is you have a module where program A wants to call program B, you can replace program B with IEFBR14 and it will just call and return. ... which reveals a bug in IBM's version.

      IEFBR14 hasn't changed in years. It is so old that its standard implementation is marked as being a 24-bit program. It doesn't actually have any 24-bit dependencies, but that's the attribute it has: run in addressing mode 24.

      So, if you bring it into a load module, the linker will see that you've included a 24-bit program, and it will drag the entire load module into 24-bit mode and force it to load into low-storage. (It will only load in addresses up to 16 MB, rather than the full 2 GBs of address space available to 31-bit programs.)

    2. 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).

    3. Re:IEFBR14 by Anonymous Coward · · Score: 0

      This is not so much an exploit of JCL's functions as a crutch to work around its limitations. The necessity to use something like IEFBR14 speaks volumes.

    4. Re:IEFBR14 by Anonymous Coward · · Score: 0

      So that's why my coworkers call me IEFBR14. I'm kicking asses when they get here.

  17. Brian is a funny name for a girl... by Anonymous Coward · · Score: 0

    Really though, I've never understood the need to use gender terms when its irrelevant.

    1. Re:Brian is a funny name for a girl... by StillAnonymous · · Score: 1

      UTF-8 doesn't do the name justice. It's supposed to have a little heart over the "i" where the dot usually is.

  18. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    One of the earliest machines I learned programming on only had 256 bytes of memory.
    (Yes, that's right, 256 B Y T E S of memory.... one quarter k of ram... less than your digital wristwatch probably has... )

    The point is the program has bloat that can be eliminated.
    You might not have to worry about it, but then again...
    Besides, keeping the knowledge of creating bare metal code is important and still very useful for a number of devices or situations, just not with most your PC desktop apps.

    Ah the old days, when I was young enough and bored enough to write relative addressed machine code for fun. (Couldn't afford the damned assembler back then.)

  19. 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 Anonymous Coward · · Score: 0

      I think my favorite abuse of a program that can do ANYTHING* including Hello World is this one:

      #include

      * What you pipe to your compiler is an exercise left to the reader.

    4. Re:Simpler "Hello World" in C? by RichMan · · Score: 1

      > Doesn't say "Hello" to me!

      It's am abuse of the rules. It's all in how you compile it.

                      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.

      See
      http://www2.latech.edu/~acm/helloworld/c.html

    5. 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.
    6. Re:Simpler "Hello World" in C? by Anonymous Coward · · Score: 0

      I've got you beat then. The complete program:

      "howdy\n";

    7. Re:Simpler "Hello World" in C? by Anonymous Coward · · Score: 0

      what part of the program is "simpler", that's what I don't understand.

    8. Re:Simpler "Hello World" in C? by julesh · · Score: 1

      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."

      jules@vengeance:~$ cat > jar.1.c
      char*_="Hello world.\n";
      jules@vengeance:~$ cc -c -o /dev/tty jar.1.c /tmp/cckQeevn.s: Assembler messages: /tmp/cckQeevn.s:13: Fatal error: can't write /dev/tty: Illegal seek /tmp/cckQeevn.s:13: Fatal error: can't close /dev/tty: Illegal seek
      jules@vengeance:~$
      jules@vengeance:~$ ln -s /dev/tty jar.1.o
      jules@vengeance:~$ cc -c jar.1.c /tmp/ccMe9S0j.s: Assembler messages: /tmp/ccMe9S0j.s:13: Fatal error: can't write jar.1.o: Illegal seek /tmp/ccMe9S0j.s:13: Fatal error: can't close jar.1.o: Illegal seek

      Doesn't work.

    9. Re:Simpler "Hello World" in C? by Anonymous Coward · · Score: 0

      Hey, i'm kinda glad it doesn't talk, a non-nagging piece of code is fine with me.

      Nagging girls, now there is a problem. I think we need to talk with the creator to get something done about that volume... preferably a remote control "mute & make me a sandwich" button.

    10. Re:Simpler "Hello World" in C? by hedwards · · Score: 1

      That's funny, I have the same problem with women. Unfriendly response and no hello either.

    11. Re:Simpler "Hello World" in C? by Anonymous Coward · · Score: 0

      On my linux box, this works nicely:

      $ echo 'char*main="Hello world.\n"; ' > a.c
      $ gcc -o /proc/self/fd/1 a.c

    12. Re:Simpler "Hello World" in C? by Spy+der+Mann · · Score: 1

      In other words, you need a f'ing compiler on your path to be able to display "hello world". We jumped from 42 bytes to nearly a meg. Reminds me of the compression contest entry where the data was hidden in the filename itself. Go figure.

  20. 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.

    1. Re:Something similar by arndawg · · Score: 1

      I'm no programmer or i didn't RTFA. But isn't the compiler suppose to do this automatically? If you just use cout>>"SUP WORLD"; and include . Obviously iostream must do the syscall somewhere behind the scenes. Why can't the compiler see that you don't need any other stuff from that library?

    2. Re:Something similar by crow · · Score: 1

      In theory, the compiler could do that, but in practice, compilers don't optimize across source files. This is especially true with separately-compiled libraries. The compiler looking at your program knows to do a function call into libc, but doesn't have the source of libc handy to optimize the call away if it's trivial. In the case of system calls, it's a little tricky, as the errno support is handled by libc. If not for errno, most system calls could be implemented most efficiently using inline assembly macros, so that no library calls would be used. That would also eliminate the option to intercept system calls to do some tricky things that are occasionally interesting, such moving to a system with different system call numbers or APIs with only a libc change (without recompiling the application).

      Generally, errno was just a bad idea. The Linux system calls do it right, in that a negative return value is the errno, but libc has to have code like:
          if ( ret
      And this gets even uglier with multi-threaded programs, as errno has to become a magic global variable with a separate per-thread version, which usually means that errno becomes a macro.

  21. GCC... by Anonymous Coward · · Score: 0

    Which will dynamic link glibc even when you need static. (Think it's nsswitch???)

  22. 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.

  23. CDC by Sanat · · Score: 1

    Back in 1970 I was programming in assembler on the CDC mainframes (3200 & 3300) in the Compass assembler language. Also it was not unusual to drop into machine code and code directly from the console and then save your program in machine code either to the printer or to the disk driver.

    Now that was hands on... and I still miss it... sigh.

    Also I programmed in Fortran and COBOL as higher languages.... but nothing like the power of assembler.

    --
    And in the end, the love you take is equal to the love you make
    1. Re:CDC by nanospook · · Score: 1

      Awww I miss PLATO and EMPIRE.. ROMS SUCK!

      --
      Have you fscked your local propeller head today?
  24. One of the first things I did by MpVpRb · · Score: 1

    When I got my first C compiler...in 1981

  25. 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 Anonymous Coward · · Score: 1, Funny

      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).

    2. 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?"
    3. Re:YES!!!! FINALLY by guyminuslife · · Score: 1

      Can I nominate parent for the Slashdot "Whoosh of the Year" award?

      --
      I don't believe in time. It's a grand conspiracy designed to sell watches.
    4. Re:YES!!!! FINALLY by commodoresloat · · Score: 1

      Can I nominate parent for the Slashdot "Whoosh of the Year" award?

      Only if you can do so using a process that is less than 11k.

    5. Re:YES!!!! FINALLY by Anonymous Coward · · Score: 0

      Call of Duty

      Yes, cause God knows what we really need on Linux are 15-year old boys who like to call each other faggots while pwning noobs.

    6. Re:YES!!!! FINALLY by tehcyder · · Score: 1

      Can I nominate parent for the Slashdot "Whoosh of the Year" award?

      I think you qualify for a mega-whoosh, on the basis that GP was clearly ironic, and misunderstanding an ironic post is more whoosh-worthy than misunderstanding a serious one.

      Then again, if *you* were being ironic, how whooshed am I?

      --
      To have a right to do a thing is not at all the same as to be right in doing it
  26. 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.

  27. In other conspiracy news... by __aaclcg7560 · · Score: 1

    With the Hello World program rewritten, scores of publishers will be updating their programming books and charging more $$$ for their new door stoppers.

  28. 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...

  29. Re:11k Is Too Big? by techno-vampire · · Score: 1
    she's probably running it on a PC with anywhere from 1GB - 4GB of RAM.

    Just because her machine has that much RAM available doesn't mean the program has to use it.

    --
    Good, inexpensive web hosting
  30. Occams Wedge by CODiNE · · Score: 1

    "Simpler" 'Hello World'?
    SIMPLER? Perhaps in the sense of using less bytes, but the article is well beyond your average first year comp sci student so it's certainly not simpler in the sense of being understandable.

    This is what I call "Occam's Wedge", what's simple to you and simple to me may be entirely different leading to a wedge in our argument with both sides insisting Occam is on their side.

    --
    Cwm, fjord-bank glyphs vext quiz
    1. 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.
    2. Re:Occams Wedge by Namarrgon · · Score: 1

      It hides the increased complexity from the programmer.

      This way, the machine spends an extra millisecond or two executing unnecessary code, which temporarily wastes 0.0005% of its RAM, and the programmer saves a good 15 minutes or more of his/her time.

      Which resources do you think are the most valuable?

      --
      Why would anyone engrave "Elbereth"?
    3. 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.
    4. Re:Occams Wedge by Captain+CowHeart · · Score: 1

      They understand the behavior on the appropriate level. I don't see any reason why reason about transistors and stuff when all you need is to turn your laptop on and play Pacman. You know how it works just enough. Eat and don't get eaten.

    5. Re:Occams Wedge by gbjbaanb · · Score: 1

      the CPU.

      simply put - the programmer takes his 15 minutes to do a quality job, and the result is better and more efficient. Over years of use of that program, the world saves hundreds of thousands in energy costs, and server hardware costs, not to mention the time saved by users who would have otherwise stared at the screen thinking "come on you bl**dy pile of c**p, 8Gig of RAM and a 3Ghz CPU and you *still* spin that damned hourglass".

      Given that, 15 minutes seems worth it. Every time I try to write a new email in Outlook, I wish those programmer had spent a lot longer than that!

      Of course, given your way - where we make it so easy for a programmer to code bloated, inefficient apps - you'll have plenty of 15 minutes to spend considering what the outsourced Indian who now has your job is doing.

  31. 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.
  32. any torrent links? by SethJohnson · · Score: 1, Funny

    Waiting for someone to crack this new hello world code and post it on bittorrent. Any links appreciated.

    Seth

  33. 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.

  34. 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 Anonymous Coward · · Score: 1, Interesting

      Oh that's bullshit. Indeed it's a problem with GCC, but it's GCC's fault, not C++ and not templates. Templates are instantiated at compile time. The compiler is complete free to throw out and not instantiate parts that are not used. Your lack of instantiations are irrelevant. The problem with GCC is when you use any of the STL or the I/O library, it pulls in the entire stream library. It doesn't have to do that, and templates are not the fault. It's the designer of this monolithic monstrosity.

    2. 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....
    3. Re:C++ is worse by Darinbob · · Score: 1

      Yeah, C++ can seriously bloat up a program fast. Most people don't care because they assume they will only ever be on a fast desktop with tons of RAM. Just the simplest of iostream usage starts pulling in lots of unused code. To trim it out you have to start adding stub functions to prune references to junk you don't need. You can also just use your own stream class instead of dealing with iostream (at least that still has some object oriented vestiges left, unlike STL).

    4. 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.

    5. Re:C++ is worse by Anonymous Coward · · Score: 0

      This is why C++ does not belong in embedded systems

    6. Re:C++ is worse by sxrysafis · · Score: 1

      Just add -fno-implicit-templates in the compiler's options and explicitly instantiate only the ones you need.

    7. Re:C++ is worse by bigrockpeltr · · Score: 1

      As far as i know the linker wouldn't (but i dont follow "compiler" advancements so I could be wrong). That's why u can do 'using namespace std;' or 'using std::cout' to only include those "functions".

      --
      $ unzip, strip, touch, finger, grep, mount, fsck, more, yes,fsck,fsck,fsck,umount, sleep
    8. Re:C++ is worse by MobyDisk · · Score: 1

      Actually, it was fstream that I was causing the problem. The embedded app didn't have a console so there was no cout. Looking back at the code, I started to use fstream then switched to regular C FILE *.

    9. Re:C++ is worse by MobyDisk · · Score: 1

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

      This is the attitude that confuses me. C++ is not larger than C. gcc is creating that perception because when you include a simple C++ header, it brings in 200k of unused libraries.

      The solution is not to use C. The solution is for gcc and/or the linker to stop importing unused libraries.

    10. Re:C++ is worse by MobyDisk · · Score: 1

      Thank you! I will definitely try that.

    11. Re:C++ is worse by MobyDisk · · Score: 1

      I have noticed that if I don't do "using namespace std" it shrinks the output, but I don't understand why a using statement would cause any change to the resulting output. Isn't a using statement merely a syntactical convenience to avoid typing fully-qualified names?

  35. Ob. quote by gzipped_tar · · Score: 1

    There's been an awful lot of discussion about what is or isn't simple,
    and people have gotten a pretty sophisticated notion of simplicity, but
    I'm not sure it has helped.
                                                              -- Ward Cunningham

    --
    Colorless green Cthulhu waits dreaming furiously.
  36. Re:11k Is Too Big? by __aasqbs9791 · · Score: 1

    Not to mention the submitter didn't read the article. It isn't Hello World, and it isn't in C (at least not by the end of the article).

  37. To answer the author's last question... by mark-t · · Score: 1

    scripts. :)

    After all, there's no strict requirement that executable files on Linux be native machine code.

  38. Re:11k Is Too Big? by Rockoon · · Score: 0

    because any real application is going to need libc.

    Real programs do not need the entire libc imported, either.

    It used to be easy to import minimal sets of dependencies, and in fact it used to be default behavior. Libraries were designed in a modular fashion so that a program that only needed the module that contained getc() didnt also pull in the module with atoi(). These days, pulling in any module from a library likely brings in every module, and its a sad sad thing that compilers, linkers, and libraries have strayed so so far from the minimalist-by-default days.

    The modern ways are bloat. Defaulting to maximal rather than minimal. I don't care that the target system has 16 gigs of ram, and its programmers who shrug it off because they have so much ram (such as you) that are the problem.

    --
    "His name was James Damore."
  39. The meaning of life, the universe, and everything by Graham+J+-+XVI · · Score: 1

    ...in 45 bytes - Impressive!

  40. 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.

  41. 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"?
  42. Sell your Seagate shares *now* ... by Anonymous Coward · · Score: 1, Funny

    ... and pile up on 64x8 TTL Proms!

  43. 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.
  44. Re:11k Is Too Big? by bsDaemon · · Score: 1

    otherwise she would have done something like this:

    #include

    void main(void) {
            while (1) {
                    malloc(sizeof(unsigned long long));
            }
    }

  45. Re:11k Is Too Big? by bsDaemon · · Score: 1

    slashdot filtered my stdlib.h, but that should be obvious to everyone here over the age of 20, I think.

  46. Re:11k Is Too Big? by symbolset · · Score: 1

    You really do have the wrong sized glass.

    An 11K program is stored on 22 512 byte blocks. Reducing the block count by 1/22nd reduces the amount of I/O required to load and execute the program by 95%. By reducing the overhead of this example even further to the absolute minimum, you can increase considerably the remaining space which can be used for important code in one block I/O. Byte counts in Ethernet frames are equally important. To give an idea of how significant this is, the Slammer Worm was 376 bytes. For an application that nearly shut down the Internet that's a pretty good example of the possible leverage of code density.

    Reducing code size is a critical factor in achieving optimal efficiencies real-world businesses use to compete against each other. It's not the only critical factor, but it is one critical factor. It's important.

    --
    Help stamp out iliturcy.
  47. Ah, hello world. by SomeGuyFromCA · · Score: 1

    Wow. When I got bored with having to write it for the 12th damn time, all I did was this:

    #include<stdio.h>
    #include<stdlib.h>
     
    int main(int argc, char *argv[])
    {
        srand((unsigned)time(0));
        char* target = "Hello, world!";
        char work = (char)(rand()%97)+32;
        int cycle = 0;
        while (cycle != strlen(target)){
            while ((work = (char)(rand()%97)+32) != target[cycle]) {}
              putchar(work);
            ++cycle;
        }
        return 0;
    }

    --
    if the answer isn't violence, neither is your silence / freedom of expression doesn't make it alright
    1. Re:Ah, hello world. by dlgeek · · Score: 1

      That's a lot faster than I thought it would be, but you're missing the '\n' that's pretty much a required part of hello world. Sadly, including that would make the program even slower....

    2. Re:Ah, hello world. by Anonymous Coward · · Score: 0

      Slashdot compiler says to include time.h and string.h or you'll have undefined behavior.

      Slashdot compiler recommends against assuming ASCII (or equivalent for 0-127) character set but applauds the attempt to be obfuscated.

    3. Re:Ah, hello world. by SomeGuyFromCA · · Score: 1

      I'm surprised Slashdot compiler doesn't bitch that I call strlen() on every loop iteration.

      --
      if the answer isn't violence, neither is your silence / freedom of expression doesn't make it alright
  48. 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.

    1. Re:Not a C program by Anonymous Coward · · Score: 1, Funny

      Step four, leave out step four to save time.

    2. Re:Not a C program by SickLittleMonkey · · Score: 1

      The second link is. The third link isn't.

      --
      main() {1;} // zen app
    3. Re:Not a C program by Chris+Rhodes · · Score: 1

      You obviously didn't understand it. The binary wasn't inappropriately formatted. It had a _start function and a main function, and used standard C calling conventions, because it was a C program compiled by gcc and linked by gcc.

      E.g.:

      gcc -nostdlib stubstart.S -o hello hello.c

    4. Re:Not a C program by erroneus · · Score: 1

      Really? And if I write code in pascal and link to a C library, am I writing in C?

    5. Re:Not a C program by Anonymous Coward · · Score: 0

      Step four doesn't exist, so I assume it's '...'. Shouldn't step 5 be 'Profit'?

    6. Re:Not a C program by Anonymous Coward · · Score: 0

      Step three, perform the functions contained in the library omitted manually. Step five, start cheating in the elf binary format.

      Step four, Profit?

    7. Re:Not a C program by azmodean+1 · · Score: 1

      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.

      You're missing something here. Linux will execute "inappropriately formatted" binaries in that it completely ignores parts of the ELF header. This is not exploitable as you could just put that same data in the .data section and make the executable slightly larger. Executing the "bad" files does not allow the executed process any additional permissions, there's no security hole here. More like BAD ELF format authors putting in unused fields that just take up space :P

      Also, while you might be familiar with all kind of assembler tricks (good for you), I for one wasn't, and I was quite intrigued.

    8. Re:Not a C program by Chris+Rhodes · · Score: 1

      How in the world did you get modded up? Especially for a non-sequitur.
      Your original comment about exploits is non-sensical. Writing your own stub routine that doesn't include the c libraries doesn't create malformed code. It also has no relation to an exploit.
      Your comments are a stream of out-and-out gibberish. Your response to my comment was non-sensical and a complete non-sequitur. If you'd actually read the article, instead of just saying you had, you would see that they replaced the assembly language gcc _start stub with a minimalist version of their own (i.e., there's no malformed code, there is no exploit, just a minimalist implementation of the compile-link cycle.)
      In short, you're a dumbass, through-and-through. You must appeal to other dumbasses, and/or have another account and spend your time modding yourself up. That's the only explanation, unless your moniker, 'erroneous', means you are deliberately trolling?
      (In which case, you're still a dumbass, but spend more time congratulating yourself.)

    9. Re:Not a C program by erroneus · · Score: 1

      Back in the day, I worked with Microware's OS-9. The compiled binaries first had to pass inspection before being loaded into memory. If the header information was wrong or if the length or various checksums did not match up, it was rejected as corrupt. I know there are ways to go here and there and everywhere when it comes to getting around security and integrity measures, but it's good to have them in general and it's good when they are verifiable. How nice would it be to have all binaries that are loaded into memory validated in this way. Such binaries tracking systems could be used to verify and validate the presence of executable modules in a system, for example, in some sort of registry system that locks away signatures of executables on a read-only network server somewhere where the OS would refuse to load stuff into memory if, after checking the size and sums of the files, if they don't match the registry query. Once again, I know, not perfect, but better than what DOS/Windows does. This sort of white-list system could only exist if the kernel were designed to inspect and respect the correct binary module format.

      Linux IS mainstream even if it's not on many desktops. White-listing executable code and other memory loaded binaries would not be a horrible preventative measure.

    10. Re:Not a C program by sowth · · Score: 1

      This is also old information. I read this 10 or 15 years ago along with linuxassembly.org. All C programmers should at least look through some of this stuff so they know how the underlying system works.

      This type of stuff would be useful for embedded programming, because linking to and needing bloated libc wastes a lot of space (and is slightly slower). Direct syscalls and static linking should be options because they are useful at certain times.

    11. Re:Not a C program by Anonymous Coward · · Score: 0

      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.

      Step 4: Profit ???

    12. Re:Not a C program by Anonymous Coward · · Score: 0

      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.

      Just as soon as you explain why executing an inappropriately formatted binary is more exploitable than an appropriately formatted one.

  49. 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!

  50. 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 Anonymous Coward · · Score: 0

      If I remember correctly, the b800:0000 region is supposed to be character to be displayed, followed by the attribute of that character, then the next char, etc. You will need to fill it on every other byte there: something like *(addr += 2) = *cp?

      Oh, and that b800 is for color mode and b000 is for mono mode.

    2. Re:Damn kids by malloc · · Score: 1

      IIRC the video segment was laid out with one byte for the colour code, one byte for the character to display; so addr should either be short * or needs to increment 2.

      --
      ___________________ I want to be free()!
    3. 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
    4. Re:Damn kids by Anonymous Coward · · Score: 0

      Indeed. I once entered a 256 byte game contest---"implement a game in 256 bytes". It's amazing how much code you can squeeze into 256 bytes if you really try.

    5. Re:Damn kids by weicco · · Score: 1

      And to save that precious memory \o/

      char *addr=0xB8000000; while(*addr++=argv[0]++);

      % gcc -o "Hello, world!"
      % "Hello, world!"

      --
      You don't know what you don't know.
    6. Re:Damn kids by aifnord · · Score: 1

      In Linux, anything a user process wants to do to interact with the outside world is done through syscalls. I don't remember the exact details and I'm too lazy to look it up, but in the case of writing data to stdout, you basically just put the number of the syscall write(), the file descriptor number, a pointer to the data and the number of bytes in various registers (possible eax, ebx, ecx and edx?) and then do an int 0x80 to make the kernel execute it all for you. Basically, the syscall has the exact same interface as write(2).

    7. Re:Damn kids by HBI · · Score: 1

      You need to use a 2-byte value or skip every other byte, as every other one is a screen attribute value.

      Otherwise, you're right.

      For MGA or Herc you'd use B000:0000 as your start segment, all others B800:0000, as you did.

      --
      HBI's Law: Frequency of calling others Nazis is directly correlated with the likelihood of the accuser being Communist.
    8. Re:Damn kids by Anonymous Coward · · Score: 0

      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.

      Ah, the wonders of protected mode that doesn't let you do great stuff like that anymore. Anyway, as far as i remeber the address is 0xb8000 and you have to increment *addr twice because the second byte is the color you want to display the first byte in.

    9. Re:Damn kids by Anonymous Coward · · Score: 0

      you forgot the attribute byte, your output would look like "HloWrd" in fancy colors/blinking .... it will work correctly when you change char *addr to short *addr though

    10. Re:Damn kids by dylan_- · · Score: 1

      You can do something like:
      .section .data
      hello: .ascii "Hello World!\n" .section .text .globl _start
      _start:
                      movl $4, %eax # what to do (sys write)
                      movl $1, %ebx # where to do it (stdout)
                      movl $hello, %ecx # what to do it with (start address of text)
                      movl $13, %edx # how long to do it for (length of string)

                      int $0x80 # call linux to do its stuff

                      # and exit cleanly
                      movl $1, %eax
                      movl $0, %ebx
                      int $0x80

      So you remembered well! (I hope I did; this should work I think!)

      --
      Igor Presnyakov stole my hat
    11. Re:Damn kids by dylan_- · · Score: 1

      That should read:

      hello: .ascii "Hello World!\n"
      .section .text .globl _start

      Not all on the one line: don't know why slashdot is joining these two lines.

      --
      Igor Presnyakov stole my hat
    12. Re:Damn kids by dylan_- · · Score: 1

      Why do I bother neatly formatting something if slashdot then screws it up, even when I use the <code> tag?!

      Oh I see, I'm supposed to use ecode instead. *sigh*

      This is roughly how it should be:

      .section .data
      hello:
      .ascii "Hello World!\n"
      .section .text
      .globl _start
      _start:
              movl $4, %eax # what to do (sys write)
              movl $1, %ebx # where to do it (stdout)
              movl $hello, %ecx # what to do it with (start address of text)
              movl $13, %edx # how long to do it for (length of string)
       
              int $0x80 #call linux to do its stuff
       
              # and exit cleanly
              movl $1, %eax
              movl $0, %ebx
              int $0x80

      --
      Igor Presnyakov stole my hat
    13. Re:Damn kids by dylan_- · · Score: 1

      ..and for completeness, if you haven't seen this stuff before (not you, that I was replying to, this is for anyone else who's curious), you can run it by:
      Save it into a plain text file called "hello.s" (or whatever you like; I've assumed that name for the rest)
      Then assemble and link with: (note that "$" indicates your prompt: you don't type it)

      $ as hello.s -o hello.o
      $ ld hello.o -o hello

      Then you can run with:

      $ ./hello

      The second-last line "movl $0, %ebx" moves the value "0" into the ebx register. Whatever is in there when you exit is the return value. You can view the return value with:

      $ echo $?

      Try changing values and see what happens. And try changing the length of the string, or frankly anything you like (it won't break anything; at worst it just won't run). Remember you need to reassemble and link the file. Use your up arrow to get the previous commands or try:

      $ !as
      $ !ld

      and note it runs that last command that started with those letters (you could just do "!a" but I prefer to use two letters just in case I've typed something I forgot about!)

      I think that's about the lot...

      --
      Igor Presnyakov stole my hat
    14. Re:Damn kids by ucblockhead · · Score: 1

      Yup, thanks. It's been many years, obviously.

      --
      The cake is a pie
  51. 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]).

  52. 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
  53. But you don't understand! by Anonymous Coward · · Score: 0

    Sure it's been done before. But this time it was done... by a woman!

    I'm not saying that's actually significant, but it seems good enuf for /.

    Case in point: http://hardware.slashdot.org/story/10/03/15/0028201/Mario-Reduced-To-8x8-With-Open-Source-and-Arduino

  54. 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"
  55. Re:11k Is Too Big? by Yvan256 · · Score: 1

    But, but... the ATmega644P costs 9.28$USD!

    And you can keep your half-sunflower seed ATtiny10, I'd rather use a DIP-8 ATtiny85!

    And your ATtiny10 is actually 1.19$USD, so don't crap on my 2.44$USD ATtiny85. ;)

    * This message was not approved nor endorsed by Digi-Key.

  56. 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.

  57. 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.

  58. Re:11k Is Too Big? by CapnStank · · Score: 1

    I agree that simplicity of code is the underlying factor here but coming from someone who's been coding in assembly for the last four hours (Shoot me, please!) I honestly don't understand why the libc library was included when not called for.

    I'm far from an expert on the intricate workings for C but I'm under the assumption that making a check if the library is required or not is fairly simple.

  59. 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.

    1. Re:Bare metal DOS? by jimicus · · Score: 1

      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.

      Not much of one by modern standards. You've got a filesystem, a command shell, character-based graphics and not a great deal else. There's a reason why Windows '9x hung around as long as it did - the sheer number of DOS applications that attempted to talk directly to hardware.

    2. Re:Bare metal DOS? by Anonymous Coward · · Score: 0

      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.

      MS DOS was a DISK Operating System. Early DOS basically took care of disk-operations and the file system (and that could be circumvented), everything else you wrote in assembler was at its highest level BIOS calls or, even more bare metal, writing/reading to/from the right memory adresses or ports. DOS took care of getting the programs into the main memory and started the execution, but the only DOS call most programs ever made was INT 20 (exit).

      MS DOS was not a real operating system.

  60. Re:11k Is Too Big? by Anonymous+Brave+Guy · · Score: 1

    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.

    I guess that's a matter of perspective. It's been nearly 20 years since I did this the first time, but off the top of my head and using nothing but debug.exe, I just produced a complete, working hello.com file in about 27 seconds. How many modern C IDEs would even have started up with a blank file in that time? (In case anyone's curious, it was 19 bytes long, which I suspect you can't beat on a Windows box without playing with video memory directly.)

    I wonder how often we add "just another 11k" to our programs today by extending your argument, and how many of them could be avoided similarly easily. Given that it takes probably a minute for a basic OS and GUI to start up and reach a useful state on a contemporary high-end PC, I'm betting it's a hell of a lot more than necessary. All that flexibility has a price, to be sure, but I suspect at least part of the problem is that we just haven't got very good at building large software systems yet, either technically, or in terms of tools, or in terms of management.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  61. Bad subject by customizedmischief · · Score: 1

    Oops! Poster misplaced the quotes. Subject should read:

    "Simpler" Hello World Demonstrated In C

    --
    Oops.
  62. Re:11k Is Too Big? by dwarfsoft · · Score: 1

    Here, I found your <stdlib.h> for you. &lt; ftw.

    --
    Cheers, Chris
  63. 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)

    1. Re:Let the lawn derby begin by QuasiEvil · · Score: 1

      One of the systems I've worked on in the last year used Microchip PIC12C508s as signal converters to interface one part to another. Basically the function could have been done with discrete logic, but why when a 25 cent, 8 pin micro will do just as well. Those bad boys have 25 bytes of RAM (yes, 200 bits, folks) and they're still an actively produced, useful part.

    2. Re:Let the lawn derby begin by KibibyteBrain · · Score: 1

      But PICs use a Harvard architecture so they are not comparable in terms of RAM to an x86 which must work completely from RAM.

    3. Re:Let the lawn derby begin by Anonymous Coward · · Score: 0

      Sometimes I use COINS to perform binary computations. Considering the economy, I'm lucky to have 16 bits to work with.

    4. Re:Let the lawn derby begin by BitZtream · · Score: 1

      I code for a processor like that ever day.

      32 registers, no RAM otherwise.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    5. Re:Let the lawn derby begin by BitZtream · · Score: 1

      Virtual memory pretty much allows the same sort of operation from a practical standpoint. Mapping IO storage directly into ram and all that.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    6. Re:Let the lawn derby begin by KibibyteBrain · · Score: 1

      Virtual memory isn't even close to the same thing. Harvard Architecture processors literally execute from ROM. Their program counter points to ROM and they literally cannot grab instructions from elsewhere in the basic architecture. The reason this is important to note is that in theory basic Harvard programs require ZERO ram to work(and indeed, a Hello World program for most Harvard microcontrollers would require none). x86 processors fetch instructions from RAM and therefore require something memory mapped at least to fetch instructions from. So saying the PIC has less resources is misleading as it uses it's resources in a different way so it's apples to oranges.

      Virtual memory is just a system feature that allows for on-the-fly access of data in ROM as if it were already in memory. It is still eventually paged to RAM, so it makes no difference in this case and isn't really comparable at all.

    7. Re:Let the lawn derby begin by TangoMargarine · · Score: 1

      Feh. Real programmers just use registers. Ever.

      --
      Unity? Screw that: XFCE. Slashdot Beta? Screw that: SoylentNews. Australis? Screw that: Pale Moon. UX developers DIAF
  64. Re:11k Is Too Big? by Rockoon · · Score: 1

    Yeah its fine that it loads the whole dynamic library when I am dynamic linking, it is not fine that it imports every module in the library when I am static linking.

    Dynamic linking has its own pitfalls (library must be there in a common location, or all is for naught)

    --
    "His name was James Damore."
  65. Simpler Hello World? by Anonymous Coward · · Score: 0

    If I were her teacher I would triple her home work for wasting time like this. I would also administer reciting ELF32 and ELF64 specs and always writing her own linker map file from scratch every time she had to run a C/C++ program.

  66. 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.

  67. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    "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.

    Agreed, if I can get 100,000 part pricing on a Blackfin 533....

  68. Re:11k Is Too Big? by QuasiEvil · · Score: 1

    Actually, no, I used to use gcc against an m68k embedded target as part of my daily job writing firmware, and 11k does matter when your total program space is only about 256k.

    Even today, I'd much rather compromise compile time for smaller, faster code on the output side. I live in the small embedded realm, though, and size is often directly related to speed due to the sloth-like nature of the memory bus.

  69. Come on, really? by ld+a,b · · Score: 1

    It took me a weekend a few months ago to write a "Hello world+cat+string manipulation+malloc+free+argv+envp" program for amd64 that worked on Linux, OpenBSD and FreeBSD with the same exact binary and no emulation using mostly C code and about a dozen lines of assembly.
    It later degraded into a posix cross-platform mini-c and objective-c 2.0 runtime library, but you can do far more amazing things than calling the exit(2) syscall in an obsolete architecture.

    --
    10 little-endian boys went out to dine, a big-endian carp ate one, and then there were -246.
  70. Re:11k Is Too Big? by Anonymous Coward · · Score: 0, Insightful

    You mean 50. The rest of the civilized world, those of us not eating tapioca pudding and watching Matlock between shifts of drooling on the keyboard, switched to better languages like C++ and Java

  71. 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. :)

  72. How on earth is this news? by seebs · · Score: 1

    It's a great article. But it's not new.

    I referred to it as a reference in something published by developerWorks in 2005.

    http://www.ibm.com/developerworks/power/library/pa-spec12/

    Shouldn't "news" be, say, less than HALF A DECADE OLD? Oh, wait. It's kdawson, who has a nearly magical power for making bad decisions.

    --
    My blog: http://www.seebs.net/log/ --- My iPhone/iPad app: http://www.seebs.net/seebsfrac/
    1. Re:How on earth is this news? by julesh · · Score: 1

      It's a great article. But it's not new.

      According to the notes attached, it's recently been updated for changes in Linux 2.6.

  73. Re:11k Is Too Big? by Lunix+Nutcase · · Score: 1

    How many modern C IDEs would even have started up with a blank file in that time?

    A ton of them? I just opened up Visual Studio 2008 in 3 seconds and Borland C++ Builder in 2.

  74. +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
    1. Re:+5, Insightful by putaro · · Score: 1

      Linux won't boot without bash installed anyhow.

    2. Re:+5, Insightful by Anonymous Coward · · Score: 0

      really? tell that to my router using busybox

    3. Re:+5, Insightful by ArsonSmith · · Score: 1

      sure it will.

      try init=/bin/yes

      it'll boot, wont be useful, but no bash.

      --
      Paying taxes to buy civilization is like paying a hooker to buy love.
    4. Re:+5, Insightful by Hurricane78 · · Score: 1

      By the way: init is the quickest way, to make your own linux-kernel-based OS from scratch. Just have a boot partition with grub and the kernel like normal. and then a root partition with just your program called trough init, and all you need around it.

      I quick trick is to use python by setting init=python or something like that.
      But I recommend starting out out with a generic hardware abstraction layer that offers a simple data graph of everything as an interface. And a generic graphical shell (using kernel-included drivers). Done right you have a good start for making your own complete OS. :)

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    5. Re:+5, Insightful by putaro · · Score: 1

      Well, if you're going to run the app, you have to get to a useful state.

    6. Re:+5, Insightful by complete+loony · · Score: 1

      Which leads to another interesting point. Put all your standard linux system binaries in the same exe and they can share all that boilerplate startup and runtime library code.

      --
      09F91102 no, 455FE104 nope, F190A1E8 uh-uh, 7A5F8A09 that's not it, C87294CE no. Ah! 452F6E403CDF10714E41DFAA257D313F.
  75. Hello Real World by Anonymous Coward · · Score: 0

    Nice, though HOTBASIC which is as powerful in scope as C and much easier in syntax does it in:

    4kb for WINDOWS. :D

    It strips everything it doesn't use. Creates the smallest, fastest exe's out there.

    Hello World !

  76. Re:11k Is Too Big? by vtcodger · · Score: 1

    ***Yeah, but the 45-byte program doesn't say "Hello World".***

    Yeah, noticed that myself. Looks to me like he/she got rid of printf, but never replaced it with anything.

    FWIW, here's a link to an 18 byte version of "hello world" machine code version from a couple of decades ago that actually displays the text under msdos and, I assume, Windows 9 when booted to a command prompt.

    I don't think we should all be stuffing bytes into memory with DEBUG. But neither do I think much of C, C++, Java which have always seemed to me like a deceptively difficult way to do simple stuff poorly. Surely there must be some middle ground that doesn't create unreliable, insecure, bloated, buggy software put together from overlapping layers of distraction. Wish I knew what it is.

    I really don't think that we live in the best of all possible worlds.

    --
    You can't see ANYTHING from a car, You've got to get out of the goddamned contraption and walk...Edward Abbey
  77. 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 Anonymous Coward · · Score: 0

      Yours does more than the article did. Yours actually prints hello world. Hers just returned 42. So I am sure you can do even better...

    3. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

      Without any context I am left to blindly type what you posted... It seemed to work until I got to this line...

      -r cx :001D
                  ^ Error

    4. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

      @Echo Hello World

      C:\>hello
      Hello World!

      C:\>dir hello.bat
        Volume in drive C has no label.
        Volume Serial Number is [xxxxxxxxxxxx]

        Directory of C:\

      17/03/2010 02:36 20 hello.bat
                                    1 File(s) 20 bytes

      To be fair, this is cheating. However, part of good programming is recognising when it's OK to cheat. :)

    5. Re:29 bytes ! Beat that !!! by omnichad · · Score: 1

      I don't see any C code anywhere. I think you missed the point. Try getting anywhere near that small with a compiler.

    6. Re:29 bytes ! Beat that !!! by bkaul01 · · Score: 1

      What's with the "xxx" directory? Programming = porn?

    7. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

      But that's a Dos program not a linux program. How addressing the text mode memory directly (address 0xb800)? Or use the int 10. Then just stick it straight into the boot sector.

    8. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

      in Autoit, a hello world looks something like this:

      msgbox(0,"","Hello World!")

    9. 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!

    10. Re:29 bytes ! Beat that !!! by noidentity · · Score: 1

      Only 18 bytes (including newline):

      echo Hello World!

    11. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

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

      From the future no less!

    12. Re:29 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

      Hi fellow DEBUG newbie! I managed to figure it out on my own...

      Type this (some of the things in the original post are what debug says, not what you type):

      debug
      a
      mov dx, 100
      mov cx, 000D
      mov bx, 1
      mov ah, 40
      int 21
      mov ah, 4C
      int 21
      ^C [press Ctrl-C here to break out of Assembly mode]
      f 111 "Hello World!"
      a100
      mov dx, 0111
      ^C [press Ctrl-C here to break out of Assembly mode]
      r cx
      001D
      n c:\ xxx\ hello.com
      w
      q

      hello.com

  78. 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

  79. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    DigiKey? You're gonna quote digikey pricing?

    You're buying a 12-oz beer at a mini-bar in your room at the Ritz, where everyone else shops at Costco...

  80. 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.

  81. Tiny others by Anonymous Coward · · Score: 0

    There's also tiny PE: http://www.phreedom.org/solar/code/tinype/
    and tiny .COM: http://board.flatassembler.net/topic.php?t=10847

  82. Even smaller using a.out format ? by dougmc · · Score: 1
    First of all, he's cheating a bit -- this really isn't a C program anymore -- it's an assembly program. Since it's apparently OK to change languages, we could simply do this --

    #!/bin/sh
    exit 42

    ... though that's obviously violating the spirit of the exercise.

    But it's possible he could make it shorter. Linux has used ELF since 1.2, but it used the a.out format before that (yes, gcc still creates a file called a.out by default, but the reasons for that are historical -- the name of the output file and the format really are unrelated.) And it looks like modern kernels still have the code for CONFIG_HAVE_AOUT even if it doesn't seem to really be enabled often anymore.

    In any event, a.out is a good deal simpler than elf. I'll bet he could make his program even shorter by using it.

    1. Re:Even smaller using a.out format ? by dougmc · · Score: 1

      To be fair, the title of the article is "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux" -- rather different from the /. title of "Simpler "Hello World" Demonstrated In C".

      The title of the article is certainly correct, and if you're sticking to ELF and don't care about your language, it's likely as small as you're going to get. But as for what the /. article said, you can likely get even smaller with a.out format, and do be aware that even the article referenced isn't doing it with C.

  83. Dynamic libraries are part of the problem by Anonymous+Brave+Guy · · Score: 1

    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.

    Given the number of functions in a library like libc and the number of programs likely to need each of them at any given time, that is probably the least convincing argument ever made for using dynamic libraries.

    On top of that, many applications wind up depending on subtly different versions of dynamic libraries, effectively reloading the same one multiple times and negating the space advantage. The alternative, as we learned the hard way, is DLL Hell.

    Moreover, other than for near-universal functionality like libc or your basic OS integration stuff, how many libraries are really used by several different programs at the same time anyway?

    Then you get to dependencies between libraries, where one "simple" library winds up pulling in half the files on your hard disk, even though nothing you're actually going to call in the main library needs any of the other stuff.

    Next up, we have performance, or rather lack of it, since you can't globally optimise over code linked to a standard library the way you can to code linked statically.

    Bottom line: dynamic libraries are, in nearly all cases, just a horrible mistake that history has yet to correct.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:Dynamic libraries are part of the problem by walshy007 · · Score: 1

      Given the number of functions in a library like libc and the number of programs likely to need each of them at any given time, that is probably the least convincing argument ever made for using dynamic libraries.

      Every process you run is using a shared library of some description usually quite a few of them, use ldd to figure it out yourself.

      Your argument basically comes down to every single program should completely reinvent the wheel by including the code to do absolutely everything itself, that, is insane.

      Yes you wouldn't be writing it yourself, but you are distributing hundreds of the exact same library, in a place (in binary) where it cannot be updated

      Moreover, other than for near-universal functionality like libc or your basic OS integration stuff, how many libraries are really used by several different programs at the same time anyway?

      at what artbitrary point do you stop calling it 'os integration stuff' when it all comes stock with most distros, I mean arguably qt and gtk are libraries separate to the 'os' same with SDL, crystalspace etc, then you go onto specific function support like libacl, libpthread, sockets, etc all of which are libraries on top of the kernel and with every linux distro.

      Library re-use is everywhere in the linux world, to think it isn't is insane.

      Next up, we have performance, or rather lack of it, since you can't globally optimise over code linked to a standard library the way you can to code linked statically.

      So... you are really going to 'optimize' things from a completely foreign codebase that you have had no prior experience to on the source tree... to try and 'improve' performance on a single part for your needs?

      You would be better off writing the needed functionality yourself from scratch in that instance, and we all know how well that goes.

      Bottom line: dynamic libraries are, in nearly all cases, just a horrible mistake that history has yet to correct.

      I for one, do not want the gigantic mess that is having everything statically compiled. From a deployment perspective on a system that likely won't have installed libraries, it's useful, but the real solution is to.. install the libraries.

      you really want every single QT app including it's own version of QT? fine, add 30mb or so to every single app that uses it's gui, same deal with gtk.

      Here's a real life program example where dynamic libraries solved a problem. Neverwinter nights, had a linux release, it used SDL for the interface and loaded the library dynamically.

      If it were static, the new outputs for sound output in SDL would not be available, but since it was dynamic, the new version can be used and huzzah we have jack and pulseaudio support.

      On top of that, many applications wind up depending on subtly different versions of dynamic libraries,

      This, is why there's a different .so extension for each time they break the api (if it's a well thought out api this should only happen once in a blue moon) This api compatibility through the symbol tables are how dynamic libraries work, and why they work so well.

    2. Re:Dynamic libraries are part of the problem by Rockoon · · Score: 1

      Yes you wouldn't be writing it yourself, but you are distributing hundreds of the exact same library, in a place (in binary) where it cannot be updated

      You've obviously never dealt with actual program distribution on a large scale and my guess is that if you've done any at all, its been to the open source world where its expected that someone somewhere will have to hunt down all the dependencies that you so flagrantly didnt bother to include.

      Even in the case of fairly standard dependencies, such as MSVCR80, you want to ship a version of it known to not have issues with your program because not everyone will have the most up-to-date copy, others may have an even later version that breaks your shit, and others may not have any copy of MSVCR80 at all.

      Shipping naked executables with none of its dependencies is amateur and unrealistic, so in the real world dynamic linking does not reduce the number of bytes needing to be distributed, that quite the contrary it increases the number of bytes needed.

      I for one, do not want the gigantic mess that is having everything statically compiled. From a deployment perspective on a system that likely won't have installed libraries, it's useful, but the real solution is to.. install the libraries.

      Listen to yourself.. you dont like gigantic messes, but have the gall to suggest that someone whos program just needs printf() and getc() should ship the entire library!

      You have not thought this through. You offering up scenarios where it makes sense to dynamic link, but completely ignoring all the cases where it makes no sense at all.

      You realize that a programmer is expected to make rational decisions, right? The problem under discussion is that the decision to static link is much worse than it should be, even much worse than it used to be.. that static linking has gone downhill into bloatedness for no good reason other than lazy library organization and poorly written linkers.

      --
      "His name was James Damore."
    3. Re:Dynamic libraries are part of the problem by walshy007 · · Score: 1

      and my guess is that if you've done any at all, its been to the open source world where its expected that someone somewhere will have to hunt down all the dependencies that you so flagrantly didnt bother to include.

      Well having your programs in the main repository IS a major advantage to code re-use, having everyone link to common code with clear cut dependencies that are automagically handled is convenient

      Shipping naked executables with none of its dependencies is amateur and unrealistic, so in the real world dynamic linking does not reduce the number of bytes needing to be distributed, that quite the contrary it increases the number of bytes needed.

      Depends on the method of distribution, to argue that the linux yum/apt way of installing software is wasteful with dynamic libraries is a very hard argument to defend. Windows has crap all commonly distributed useful libraries so it's all statically linked because each author thinks "bah, what user of my software would already have it installed" thusly it never gets installed, repeat.

      Even in a far from ideal windows environment, there is nothing stopping your installer from checking at install time if dependencies are there, if they are at least the required version, and if not launching another installer for the library. Yes The distribution of bytes would be larger but the actual installed size would be smaller due to it only ever being installed once.

      Remember when directx was new and launchers would offer to install directx? similar but with libraries and more auto-detection

      You offering up scenarios where it makes sense to dynamic link, but completely ignoring all the cases where it makes no sense at all.

      If you read the post above my initial one, I was responding to this:

      Bottom line: dynamic libraries are, in nearly all cases, just a horrible mistake that history has yet to correct.

      Considering the way the linux software ecosystem works, it's hard to say that it's horrible for all cases yes? considering dynamic linking is the default way to do things for efficiency and it all just works.

      Of course I'll grant you that for extremely obscure 'no-one is really going to need this' libraries, on windows. Static linking could be quite preferable. Especially when the libraries are proprietary and not meant for reuse.

      The problem under discussion is that the decision to static link is much worse than it should be, even much worse than it used to be.. that static linking has gone downhill into bloatedness for no good reason other than lazy library organization and poorly written linkers.

      I stepped in when I heard someone pipe up saying dynamic linking sucked for nearly all situations, for windows machines perhaps but far from it in linux/bsd/etc.

    4. Re:Dynamic libraries are part of the problem by Rockoon · · Score: 1

      Considering the way the linux software ecosystem works, it's hard to say that it's horrible for all cases yes?

      its not that hard at all. You are only focusing on a specific portion of the linux ecosystem, that being distribution specific repositories.

      Its all fun and games when someone else has made sure all the dependencies are there, and that they are compatible with everything. Then its real easy to declare that dynamic linking rocks, because you didnt have to do any of the actual work to make it 'just work'

      --
      "His name was James Damore."
  84. 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
  85. 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.

    1. Re:The summary headline is crap by Sancho · · Score: 1

      It's worse than that. The third link isn't even by the same author. It's just another example of making a tiny ELF executable, and it appears to be completely unrelated to the MIT student's example.

  86. GNU Hello World by kriston · · Score: 1

    I always enjoyed the GNU Hello World packages in C and C++. They seem too large for their purpose, but I supposed they were trying to test something under the surface.

    --

    Kriston

  87. Re:11k Is Too Big? by Anonymous+Brave+Guy · · Score: 1

    I'm sorry, perhaps I should have explicitly included the time to create all the solution/workspace/project/perspective/whatever junk that modern IDEs use in my definition of "started up with a blank file".

    In any case, the point I was refuting was the claim that to get rid of the 11k, you'd have to "make real programs either slower or bigger, or make compilation slower". I contend that in no modern C IDE can you create and build a working "Hello, world!" program that is superior in any of those respects to my insta-.com version.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  88. Re:11k Is Too Big? by Anonymous Coward · · Score: 1, Funny

    Hahaha, wtf? That was actually an apt car analogy.

    Now, get off my lawn!

  89. Re:11k Is Too Big? by innocent_white_lamb · · Score: 1

    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?
     
    For the sake of comparison to modern compilers, I just compiled hello.c with Borland Turbo C 2.01 for DOS (copyright 1987/1988) and got this:
    wc -c hello.exe
    5676 hello.exe
     
    Removing the printf and simply assigning the text to a pointer (as she did in her "second try") got me this:
    wc -c hello.exe
    4332 hello.exe
     
    Changing to the "tiny" memory model from the default "small" got me this:
    wc -c hello.exe
    4396 hello.exe.
     
    Looks like ELF defaults to using roughly twice as much ram as MZ did(does) in DOS. On the other hand, ELF may be doing more setup stuff than MZ -- I don't know enough about the nuts and bolts of that to be sure. I do know that the MZ header is pretty simple...

    --
    If you're a zombie and you know it, bite your friend!
  90. Dupes. by http · · Score: 1

    I remember this from years back. Do the editors not have a sense of history?
    http://linux.slashdot.org/article.pl?sid=02/10/19/1233250

    --
    If opportunity came disguised as temptation, one knock would be enough.
    3^2 * 67^1 * 977^1
  91. 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.
    2. Re:Did similar back in MS-DOS 2.11 by mlosh · · Score: 1

      IIRC, a .com had to have code to fit entirely in a 64Kb memory segment, and had a fixed default memory map for the code, stack and data segments. This means the loader did not need to do any fancy relocation, so there were no relocation tables and a much simpler executable header structure (nearly(?) absent for a .com).

    3. Re:Did similar back in MS-DOS 2.11 by Anonymous Coward · · Score: 0

      All addressing was done in 16 bits so it was the fastest form of execution. Also if you had two programs with the same name but different extensions the .com form would always take priority.

  92. Duh! by Anonymous Coward · · Score: 0

    Please tag this article with "duh".

  93. Could it be? by WidgetGuy · · Score: 1

    I think I'm in love.

    --
    One "Aw, Shit!" is worth 100 "Ata boys!"
    1. Re:Could it be? by cpscotti · · Score: 1

      =/
      I thought it was only me!!
      I'm totally in love!

      What am I doing wrong with my life so that I don't even know her?! pretty much everything probably!

      Jessica, I love you!

  94. A dupe? by DollyTheSheep · · Score: 1

    Did not read TFA, but some years ago there was astory about the smallest possible ELF program, which sounded very similar or the same as the summary of TFA: a tiny program, that doesn't output anything, but doesn't need any libraries either nor does make any sxstem calls. So, it's probably a dupe!

  95. She? by Anonymous Coward · · Score: 0

    And it's written by a Brian Raiter. Where did 'she' come from?

    1. Re:She? by JSBiff · · Score: 1

      What's written by Brian Raiter? The blog post that slashdot linked to had the following author info line:

      >>>Posted in computer architecture on March 16th, 2010 by Jessica McKellar.

      I've personally never met a man named Jessica (unless you count a drag queen), so I'm defaulting to 'she'.

  96. 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!?"

  97. Re:11k Is Too Big? by Philip_the_physicist · · Score: 1

    if you want c++ cstdlib would work, and that's ignoring that C is still a good language for some important fields (like kernels and bit bashing).

  98. MSDOS by Anonymous Coward · · Score: 0

    >debug hw.com
    File not found

    -a
    13BE:0100 mov ah, e
    13BE:0102 mov bp, 110
    13BE:0105 mov al, [bp]
    13BE:0108 int 10
    13BE:010A inc bp
    13BE:010B cmp al, 64
    13BE:010D jnz 105
    13BE:010F ret
    13BE:0110
    -e110
    13BE:0110 43.48 4F.65 4D.6c 53.6c 50.6f 45.20 43.57 3D.6f
    13BE:0118 43.72 3A.6c 5C.64
    -rcx
    CX 0000 :1b
    -w
    Writing 0001B bytes
    -q

    C:\DOCUME~1\Steve
    >hw
    Hello World
    C:\DOCUME~1\Steve
    >dir hw.com
      Volume in drive C has no label.
      Directory of C:\DOCUME~1\Steve
    03/16/2010 10:22 PM 27 HW.COM

  99. 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

  100. Re:11k Is Too Big? by Philip_the_physicist · · Score: 1

    One is hello world, mostly in C, the other is an example of abusing the ELF standard to create a 45-byte executable to return 42. THe submitter did RTFA, he just didn't phrase the summary well.

  101. Re:11k Is Too Big? by IorDMUX · · Score: 1

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

    As a hardware engineer in the mobile industry, I agree fully. Whereas the 1990's were about powerful PC's beginning to enter every home, the 2000's were about powerful communication devices beginning to enter every pocket, the next ten years will (I hope!) be about systems of these tiny systems revolutionizing our idea of a "computer".

    --
    >> Standing on head makes smile of frown, but rest of face also upside down.
  102. It just works by Anonymous Coward · · Score: 0

    It compiles to 13340 bytes on OS X.

  103. 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 :(

  104. You must call user comments to read Slashdot by lmnfrs · · Score: 1

    You thought the headline and summary described the article without calling user comments? :\

  105. Re:11k Is Too Big? by ari_j · · Score: 1

    How to tell the summary contains inaccuracies: It talks about "programming bare-metal on DOS" - if DOS is relevant to your programming, then you are not targeting the bare metal any more than you are when you write a Python script.

  106. 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
  107. Re:11k Is Too Big? by techno-vampire · · Score: 1

    True, but that's no excuse for a compiler/linker to bring in a library that's not needed.

    --
    Good, inexpensive web hosting
  108. 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

  109. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    My Atari 2600 console has 128 bytes of memory. (Yes, that's right, 128 B Y T E S of memory.... one eighth k of ram... exactly H A L F the memory of the machine the parent used to program on... )

  110. Re:11k Is Too Big? by GunFodder · · Score: 1

    It can be difficult to determine the size of a program when you are first starting to write it. Obviously it would be faster to hack together a trivial program like "Hello World" in a simple text editor. IDEs are more useful when you are solving non-trivial problems, like maintaining a couple hundred source files and integrating dozens of external libraries.

  111. Re:11k Is Too Big? by amRadioHed · · Score: 1

    If that's the point of the article (which I don't think it is) then it does not make the case very well. You would need to show how that overhead scales with larger programs. Sure an extra 10k of code for Hello World is a lot, but if KDE only has 10k overhead I'd be pretty damn impressed.

    --
    We hope your rules and wisdom choke you / Now we are one in everlasting peace
  112. Re:11k Is Too Big? by amRadioHed · · Score: 1

    I disagree, I'd say the embedded programming style is inferior. There's nothing stopping regular programmers from coding the way they do so it would be done if it had any value. The embedded guys don't write unportable assembly because it's better, they do it because they have to.

    --
    We hope your rules and wisdom choke you / Now we are one in everlasting peace
  113. Re:11k Is Too Big? by geminidomino · · Score: 1

    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

    I see it from the opposite perspective. I've never programmed for an embedded device (The closest I've come is dicking around on some code for the GP2X). Embedded, real-time, and high-performance projects might not be the general case, but they are important nonetheless.

    But whenever it comes you, you get idiots like ILuvRamen above who post bullshit like "Use a real language, like $IDIOTS_PET_LANGUAGE" with the same canards that CPU speed and RAM are cheap now, etc... completely disregarding that, with each iteration, that the same attitude on the part of OS developers eats up a good part of the increased resources.

    Fancy toolchains and build tools are amazingly convenient, but to never know how to work without that net in case its needed is just laziness. If you personally don't ever intend to code for a micro-controller, fine, don't learn.

  114. 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)
  115. 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.

  116. Re:11k Is Too Big? by DMiax · · Score: 1

    If 11k is a problem you should not compile with gcc using linux system calls. In fact, if you are programming microcontrollers you will/should have a build chain that does not include "bloat".

  117. Re:11k Is Too Big? by JaumPaw · · Score: 1

    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.

    Well, throwing windows out of your laptop seems more fitting to the general spirit of slashdot.

  118. 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?
  119. Re:11k Is Too Big? by Lord+Bitman · · Score: 1

    sounds like you need a new compiler/language. Aren't we, as programmers, intended to be too lazy to make compromises like that?

    --
    -- 'The' Lord and Master Bitman On High, Master Of All
  120. Re:11k Is Too Big? by polar+red · · Score: 1

    are you here to kill bill (gates) to prevent windows 9 from happening ?

    --
    Yes, I'm left. You have a problem with that?
  121. Re:11k Is Too Big? by lorenzino · · Score: 0

    Not to mention the fact that building will be much faster (linking).

  122. 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.
  123. July, 1999... by pedantic+bore · · Score: 1

    So, this was written in 1999... But it's a nice read; clear and well explained.

    But has anyone tested to see whether Linux still doesn't check ELF executables for nutty stuff like this? It's come a long way in the last decade...

    (Since I don't have any x86 boxes handy, I'm just going to have to trust someone else to try it...)

    --
    Am I part of the core demographic for Swedish Fish?
    1. Re:July, 1999... by azmodean+1 · · Score: 1

      I "sang along at home" and compiled/executed the programs on a Pentium D system running Debian squeeze/sid, kernel is 2.6.31-ish. Everything worked as advertised, though the filesizes for the earlier examples were MUCH larger (about 2x). The final crazy-compacted nearly hand-assembled ELF file was the stated size.

      Why SHOULD Linux check the fields it isn't interested in? That's a great way to break backwards-compatibility of programs that try to use new features. Now if you do something non-standard, your program won't be forward-compatible in case Linux STARTS caring about those fields, but that's on the programmer's shoulders. From what I read in the article, many of the ignored fields are "reserved for future functionality", which is specification-ese for, "allow absolutely any content to be placed here until further notice".

  124. 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.

    1. Re:Hey, I heard that Windows isn't the only OS... by BitZtream · · Score: 1

      For reference, all cars in america after 1996 (Anything with ODB-II) is almost certainly powered by a process that is roughly 500 times slower clock rate, probably not even 32 bit, and closer to 1/10,000th the RAM. There is probably less non-volital storage on them than a common autoexec.bat file from the Win95 era takes up.

      On some of these devices, there is so little ram that you can't even USE C because they have no stack pointer and nothing more than processor registers for storage of data.

      Your view of programming langauges changes more than slightly when you start talking about doing things in 32 bytes of ram, total, for everything. Keep it mind, thats the amount of ram required to 11 pixels on a Windows display. Thats not even enough memory to draw the blank space between the closest letters on the screen you're looking at!

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  125. Re:11k Is Too Big? by Wovel · · Score: 1

    You do realize he said "real" programs. Your hello.com is not exactly what he was referring to.

  126. 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.
  127. Re:11k Is Too Big? by fractoid · · Score: 1

    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.

    Exactly. Sure, the initial example was what it says on the tin; a simple 'hello world' in C. Through the iterations, though, it lost every single part of that. I'd argue that the final implementation wasn't "simple" in any way except byte count, given that it required some in-depth knowledge of, and then bending of, the ELF spec. The final implementation was not simpler (to a human, given that it required some in-depth knowledge of, and then bending of, the ELF spec). It was not "hello world" (it just returned an integer), and it was not in C.

    False advertising. :(

    --
    Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
  128. What's the significance of this? by Eraesr · · Score: 1

    I'm not entirely sure I understand the significance of this.
    So she shaved a few bytes off of an executable. It takes my 2010 Internet connection roughly 0.003 seconds to download those few bytes.
    Also, if I understand correctly she shaved off a more or less fixed number of bytes, not a percentage of the original file size.
    In other words, if she performed this trick with a large and complex piece of software that generated a 1Mb executable, she'd still shave off a handful of bytes, no? Is that worth the effort? I get that it's interesting from a hobbyist perspective, but in the real world, it's rather insignificant if you ask me.

    1. Re:What's the significance of this? by Anonymous Coward · · Score: 0

      Hand in your GeekCard and don't let the door hit you on the way out.

      BBye!

  129. Re:11k Is Too Big? by Pollardito · · Score: 1

    Honestly no one probably ever conceived of someone writing a program that didn't use libc, because who would really not need parts of it? If you're not writing something to the screen or a file your program is not really doing anything, and both of those operations require libc. A program with no output is one that is saying "Hello World" to itself silently and then exiting at some point. Everything that it did during its execution might as well have been skipped, because it has nothing to show for it.

  130. Re:11k Is Too Big? by Carl+Drougge · · Score: 1

    On a decently configured modern system using a less than modern filesystem. Which isn't really the best kind of decent configuration for all situations.

  131. AppleScript version is fun by gig · · Score: 1

    say "hello world"

  132. 512, 1k, 4k by HonIsCool · · Score: 1

    Maybe check out the demo scene where 512-byte, 1k, or 4k productions are common?

    --
    "Give me six lines of C++ code written by the most competent programmer, and I will find enough in there to hang him."
    1. Re:512, 1k, 4k by eulernet · · Score: 1

      Or even better: 256 bytes !
      The original site disappeared, but here is an archive:

      http://web.archive.org/web/20071006061206rn_1/www.256b.com/home.php

  133. One conclusion by StripedCow · · Score: 1

    After reading the article, there's only one conclusion:

    Linking stuff using gcc is horribly ugly!

    --
    If Pandora's box is destined to be opened, *I* want to be the one to open it.
  134. OLD OLD OLD by sudog · · Score: 1

    Could you post an older webpage to the front page of Slashdot?!

    Geez, this thing has been around for frickin ages..

  135. Re:11k Is Too Big? by smallfries · · Score: 1

    It's in the middle, next to the link to the Japanese page. The author got a 57 byte Hello World, and compares it to the older version by the Japanese author that was 58 bytes. The 45-byte version just strips out the string.

    --
    Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
  136. 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...

  137. Re:Apple defines system call APIs at the top of li by Rockoon · · Score: 1

    Your problem is that you are detailing the pros of dynamic linking and the cons of static linking, but not detailing the cons of dynamic linking or the pros of static linking.

    Dynamic linking has put 3 different versions of VC's runtime on this computer in front of me, and thats starting from 18 days ago with a fresh installation of Win7/64.

    Also, you seem to think that its the OS's job to maintain C libraries? REALLY??! You know that C is just a programming language, right? That there are various competing compilers, right? Each with its own libraries, right?

    --
    "His name was James Damore."
  138. Yes by Anonymous Coward · · Score: 1, Informative

    Later on, I will have been going to be sent but another AC will come back afterward to stop vtcodger (957785) from linking to The Source before you have reason to send me. You don't remember because back then it was only a prophecy but now, in the future, the past has occurred.

    1. Re:Yes by Tubal-Cain · · Score: 1

      ...sent but another...

      I need either more sleep or more caffeine. I read that as "sentient butter".

  139. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    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?

    Nope. It doesn't have anything to do with your computer, it's a result of the target OS you compiled it for.

  140. Re:11k Is Too Big? by Rockoon · · Score: 1

    Why doesnt that matter?

    You seem to be focused on memory footprint, and not total footprint.

    Do you ship only the memory footprint the end user will need when running your program, or do you actually have to ship the whole executable?

    yeah.. rhetorical question..

    Seriously.. this whole "doesnt matter" attitude is the root of the bloat problem.

    --
    "His name was James Damore."
  141. 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?

  142. Re:11k Is Too Big? by KritonK · · Score: 1

    ***Yeah, but the 45-byte program doesn't say "Hello World".***

    Not only does it not say "Hello World", it doesn't even run. I tried it on a Fedora 11 system with kernel 2.6.30.10-105.2.23, and the last two versions of tiny.asm die with:
    Killed
    137
    The "file" command claims that the tiny executable is "ELF 32-bit invalid byte order (SYSV)", which probably explains why.

    The shortest version that does run is the 64 byte version, but, even for that, the "file" command has bad things to say: "ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, corrupted section header size".

  143. Whole article misses the point I think. by Anonymous Coward · · Score: 0

    The article makes it sound like it's something ingenious to write a 'hello world' that way or that it's about some practise that is useful for usual programs, yet it's rather just an example on how to get tiny executables due to avoiding linking with the C stdlib and still doing a bit of output. I see this rather as a demonstration of a technique that's maybe interesting for code for specific devices that require such stuff etc.
    It's not about: 'Hey, I've made the most ingenious smallest 'Hallo World !' or meant as something that everyone might want or needs to use somehow, it's kind of a tutorial to write code that requires something like that. So same level as tutorials about how to hook api functions and all that in windows or other 'tricks' someone might need in some situations.
    So mmh. just my 2 cents.

  144. Re:11k Is Too Big? by Slashcrap · · Score: 1

    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.

    Since you don't understand filesystem basics, I would recommend that you refrain from commenting on articles about sophisticated assembly optimisations. Seriously, it's unlikely to go well for you, as we have just seen in rather spectacular fashion.

  145. The point of hello world is to print hello world by mrjb · · Score: 1

    So she got rid of the stdlib library, but the program no longer actually prints "hello world" (or do anything for that matter, except exiting).

    Although it's interesting to see how to get rid of 11k of bloat, the program doesn't actually *do* anything anymore... so I suppose the code is still bloated, as at this point it should be possible to optimize away

    char *str = "Hello World";

    as well.

    I suppose if she wanted to actually print anything again, she'd roll her own printf function? Great for educational purposes, and it's a good thing that was the intention. Because in any production environment, it's most likely not worth it to spend this much effort on 11kB of bloat.

    --
    Visit http://ringbreak.dnd.utwente.nl/~mrjb/growingbettersoftware to download your free copy of the book
  146. Wow, er, how is this special? by Ihlosi · · Score: 1

    What's this doing on slashdot?

    I've written whole projects on microcontrollers (in C) that do much, much more than "Hello World", in less than 10 kB.

  147. Re:11k Is Too Big? by bytesex · · Score: 1

    1) Smaller is /always/ better, 2) Embedded people like compilers too, and resent them for not quite doing what they advertise, or /could/ do, given some twiddling. I, for example, would think it quite cool if you could arrange for gcc to actually produce those 45 bytes of program, given the right switches but as it is now, you can't.

    --
    Religion is what happens when nature strikes and groupthink goes wrong.
  148. 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...)

  149. Re:11k Is Too Big? by complete+loony · · Score: 1

    The better of the more recent file system designs will pack multiple small files and other filesystem meta data into that 4k page.

    --
    09F91102 no, 455FE104 nope, F190A1E8 uh-uh, 7A5F8A09 that's not it, C87294CE no. Ah! 452F6E403CDF10714E41DFAA257D313F.
  150. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    Why? Isn't the money better on the first one?

  151. Goes to show ... by Qbertino · · Score: 1

    Goes to show that C is nothing but a bunch of bloatware and the c advocates nothing but a bunch of hypocrites. This will shut them up once they come to me ragging on Python or PHP again. Ha!

    --
    We suffer more in our imagination than in reality. - Seneca
  152. 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.
  153. exe vs com by Anonymous Coward · · Score: 1, Informative

    There were a discussion at some game dev forum a few years ago, using VS60 (which compiles to win32 exe) some person come up with a ~400 bytes exe file (doing nothing).

    Using DOS, a 14 bytes program is enough:
    MOV AH,09
    MOV DX,0108
    INT 21
    RET
    DEC AX
    DB 65
    DB 6C
    DB 6C
    DB 6F
    DB 24
    -------
    14 bytes.
    With INT 21 (requires DOS). A couple more if only using BIOS/INT10 (no OS), must then print each char as individual characters, cannot print a whole string in 1 call.

  154. 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
  155. Re:11k Is Too Big? by makomk · · Score: 1

    Not only does it not say "Hello World", it doesn't even run. I tried it on a Fedora 11 system with kernel 2.6.30.10-105.2.23, and the last two versions of tiny.asm die with:
      Killed
      137

    That could be something to do with the shorter version assuming that marking memory as readable will also imply that it's executable. This used to be true on x86 but isn't anymore.

  156. Re:11k Is Too Big? by SharpFang · · Score: 1

    Yep, that would be okay if you took a ready-made car. But compiling is more like car assembly process. Compiling a program is like you tell what parts should go where, you add your engine and get it running smoothly.

    In this case, you tell the engineers you want a mock-up frame of bare essentials to have this bare engine you provided started. You expect them to attach the starter motor, the power from the battery, ignition switch, some frame to attach it to, and a pipe to a bottle of fuel.

    Instead, what you get is a car with a complete gearbox, electric installation, steering and brake system and pretty much all the basic essentials needed to drive (no extras like AC, airbags or ABS). You didn't ask for anything of that and you wanted to use the engine to power a stationary water pump and the whole "car stuff" really gets into the way.

    --
    45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
  157. Re:The point of hello world is to print hello worl by BarryNorton · · Score: 1
    Actually, I believe the point is to print "hello, world".

    I don't know where this 'hello world' everyone is talking about is, but it sounds awfully friendly.

  158. Re:11k Is Too Big? by KritonK · · Score: 1

    This used to be true on x86 but isn't anymore.

    This was on an x86 (a pentium 4), so my guess is that Linux no longer ignores some of the bits that the author claims that are ignored, which is why I mentioned the distribution and kernel version.

  159. How is this news? by rew · · Score: 1

    The article was written in 1999 (note how I have to be exact by including the millennium in the year!), and corrected in '01 and '09.

  160. Re:11k Is Too Big? by rew · · Score: 1

    The problem with demand paging is that bigger programs end up with small parts of each page that ARE used, while most of a page is unnecessary.

    Someone needs to write a profiler that figures this out, and then allow gcc or the linker to take the profile to put all the actually used parts together and the unused (or little-used) parts somewhere else.

    Similarly, demand paging back in '2000 (around when the article was written) caused a 7Mbyte binary to be read into memory non-linearly. All the seeking makes the loading slow. I and at least one distribution used to have a "dd if=netscape.bin of=/dev/null bs=64k ; netscape.bin $*" as a shell script instead of netscape. This would load all 7Mbytes into the cache circumventing demand paging which was much slower....

    Having the important bits together in say the first megabyte would get us the best of both worlds.

    Moreover, with faster harddrives we should be moving towards larger page sizes. Although the hardware has 4k pages, we should use 8k software pages adjacent page table entries are always set (almost) the same! This means that demand paging will fetch 8k at a time. Fetching a 4k page from a harddisk costs you an 8 ms seek time, 4 ms rotational latency, and .05ms for the actual transfer of the data. If we transfer 8k at a time, we go from 12.05ms to 12.1 ms. An increase of less than a percent.

    On a modern system fetching this extra 4k comes at a price (besides the 0.05 ms extra transfer time). We'll have to forget about another 4k chunk of memory. However, if we achieve a 1% higher hit-rate on the just-transferred 4k chunk than on the chunk we just discarded, we'll be winning! So if we are able to evict memory that hasn't been used for say over a minute, we're very likely winning over the current strategy.

  161. nope by Anonymous Coward · · Score: 0

    For F*ck's sake, you idiot. DOS was never "bare-metal".

  162. Re:11k Is Too Big? by philfr · · Score: 1

    This is a lame excuse for writing bloated code...
    "Anyway the compiler will f*ck it up, so why bother ?"

  163. Re:14 bytes ! Beat that !!! by Anonymous Coward · · Score: 0

    mov ah,9
    mov dx,108
    int 21
    retn
    db 48, 65, 6C, 6C, 6F, 24

  164. Stop the Hate, be constructive. by Anonymous Coward · · Score: 0

    At the time of writing this comment, I'm disgusted by the amount of flames rated +5. "Haters gotta hate", sure, but haters gotta be modded-up? What ever happened to constructive criticism? Of building some better explanation from a weak article?
    I come to Slashdot for the interesting and insightful discussions. Criticizing without anything constructive serves only in inflating your own ego.

    I believe this article is interesting. Though it does cover part of the same subject as the Whirlwind Tutorial, it doesn't duplicate it. It provides insight in the backstage of C programs which many programmers aren't aware of. I certainly wasn't aware of it before reading the whirlwind tutorial a few years ago, and there's always a new generation that can learn from it

  165. Simpler? by LaminatorX · · Score: 1

    This is definitely a smaller program, but I wouldn't characterize overlapping functionality with header address space in assembley "simpler."

  166. I now program in Java by croftj · · Score: 1

    If you have to ask questions about how much memory your program uses, you can't afford it.

    In Java, the simplicity is that you write code (preferably something abstracting someone elses code) and don't let little things like memory and performance bother you.

    Now back to reality, it's interesting as an experiment, but in all practicle purposes for what? If you are running on an OS such as linux or windows, use the services they offer you. Why invent the wheel? Certainly, why write in assembly code? Now if you are running on a AVR or the like (yes, I do that) I can see why some would go and use assembly, but still, even then I use C/C++ It's amazing what you can stuff into 32K of flash and 2K of ram

    --
    -- Many men would appreciate a woman's mind more if they could fondle it
    1. Re:I now program in Java by geekoid · · Score: 1

      You are a crappy programmer. Part of a whole group of people who don't understand what they are doing that call themselves programmers.
      Also, you are clearly not working on any complex systems.

      The rest of your post really shows how dim you must be. Do you really thinking understanding what goes on under the hood has no value? do you really think everyone programs sloppy just because it's going on a box with several gigs?

      I can't imagine you do anything with AVR that's really any good.

      Let kn know when you need to write a complex system under 640K that orbits the planet.
      Then you can tell me how it's of no use to understand what goes on under the hood.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    2. Re:I now program in Java by croftj · · Score: 1

      8P~~~~~~~~~~~

      (Yes, I sank to your level with my equally meaningful response.)

      --
      -- Many men would appreciate a woman's mind more if they could fondle it
  167. How about 28 bytes?! by Anonymous Coward · · Score: 1, 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 :001C
    -n c:\ xxx\ hello.com
    -w
    -q

    c:\ xxx>hello.com
    Hello World

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

    What do I win?

    1. 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

    2. Re:How about 28 bytes?! by fatcow · · Score: 0

      How about 21 bytes?

      C:\>debug
      -a 0100
      0D39:0100 MOV AH,09
      0D39:0102 MOV DX,0108
      0D39:0105 INT 21
      0D39:0107 RET
      0D39:0108
      -e 0108 'Hello world!$'
      -r cx
      CX 0000 :15
      -n hello21.com
      -w
      Writing 00015 bytes
      -q

      C:\>HELLO21.COM
      Hello world!
      C:\>dir hello.com
      17/03/2010 10:48 22 HELLO21.COM

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

      Why did you put it in your porn folder?

  168. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

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

    So, how's the weather in Redmond today?

  169. My (hello) world is smaller than yours by FrankDerKte · · Score: 1

    My (hello) world brings all the boys to the yard,
    And their like
    It's smaller than yours,
    Damn right it's smaller than yours,
    I can teach you,
    But I have to charge

  170. Re:11k Is Too Big? by owlstead · · Score: 1

    Yes, and many people here are all to ready to let the key only activate the starter, and not the airbag, traction control and radio too, and call them bloat to boot.

  171. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    Real programmers know that the code is also the comment

  172. Re:11k Is Too Big? by Yvan256 · · Score: 1

    Where else than Digi-Key? With Mouser Electronics, shipping to Canada is much higher than with Digi-Key.

    Where do you buy parts, Mr. Smarty Pants?

  173. 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.

    1. Re:It won't remove them unless you tell it to by MobyDisk · · Score: 1

      Is there any downside to this? Slower compile + link time maybe?

  174. Re:11k Is Too Big? by caerwyn · · Score: 1

    I think this is largely a function of how OOP is taught- including the languages used to teach it. Too many people start with Java and its "everything is an object! but they're not all first-class objects! and we're going to try to hide it all from you even though you have to know the details anyway!" design principles instead of a language that either a) cleanly mixes OOP in with procedures *not* tied to objects, or b) is a fully OOP-supportive language in which everything really is a first-class object.

    Instead we get "Java is OOP, C is not" when in truth you can easily do non-OOP programming in Java and OOP programming in pure C (and, as you pointed out, a lot of C from quite a ways back shows a lot of the features of OOP programming).

    --
    The ringing of the division bell has begun... -PF
  175. "She" ? by Derek+Pomery · · Score: 1

    'This subsection of the Muppetlabs website is maintained by Brian Raiter (aka Organic Worker Drone BR903), who is the author of the contents where not otherwise indicated. '

    Since no one else was indicated that I could see. (And, yeah, was kinda fun to reread this after all these years) seems odd to assume Brian is a she...

    --
    -- perl -e'print pack"H*","6e656d6f406d38792e6f7267"' /. ate my old sig. Bastards.
  176. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    C++ is not "better" than anything. C has its place, as does Java. C++'s place is the trash.

  177. Re:11k Is Too Big? by sp0tter · · Score: 1

    perhaps I am missing something, but I never thought of "Hello World" as program. It is more or less a concept or an experiment I use to get my first grasp on a language or tool chain. It is constantly rewritten so that each time I use it, I gain a solid understanding of the basics of how to program in a specific instance. The author is simply applying this tool to assembly.

    --
    you don't eat crackers in the bed of your future--or else you'll get all scratchy
  178. Re:BTDT... we did this in RSTS/E by lenski · · Score: 1

    ... using RSX emulation. I can no longer remember the compiler we used . Maybe Whitesmiths? But I do remember needing to implement a really basic :-) stdio library.

    By the time we were finished with the project, we had implemented a client-server data management system (it could not be called a database) that supported transactions, ordered indexes and never lost a record through years of operation.

    The company ended up replacing a PDP-11/73 with a SparcServer 2 in 1990, I think.

  179. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    Whenever a file is stored on a hard disk the space it takes up is normally 'rounded up' to the next larger multiple of the disk file allocation unit, which varies somewhat depending on the filing system and the size of the hard disk in use. But a common figure nowadays is a 4K allocation unit. So even a 0- or 1-byte file will probably take up 4K. If your disk uses 32K allocation units (an extreme case, as far as I can tell from a quick check) then you could almost triple the size of this hello world file without using any more space. So in practice, trying to make one already tiny file even smaller amongst the hundreds of thousands of other sub-4K files also present on a typical system is completely pointless.

  180. 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.

  181. Re:Apple defines system call APIs at the top of li by siride · · Score: 1

    No, it's the OS's job to maintain an interface to its functionality and that is done, for historical reasons, via the C standard library on POSIX-type systems. Windows uses another set of libraries as the main interface, upon which the C standard library is built. I find the idea that you can make system calls directly on Linux a bit strange. It's really the odd one out. All other client-server models require a library on the client end. And almost every program on Linux does use such a library. So why the fuss?

    Additional points:

    But you have to remember, C isn't just another programming language. It's pretty much the closest thing to assembly without actually being assembly. So it's a darn good choice for the system libraries because any other language can easily access the interface. If the interface where in some more complicated language, it'd be a pain and probably require a lot more overhead.

    Competing compilers can still use the same C standard library, so that concern is irrelevant. If they really really want to use their own special C standard library, they can still do that...but they have to make system calls via the system one. Big deal. One extra library (which you don't have to use if you don't want that kind of bloat).

  182. Re:11k Is Too Big? by lenski · · Score: 1

    Being happily ensconced in the bare metal world (Cortex-M3: Nice machine), I would be careful about using the word "inferior".One starts to count bytes and k's when the *entire system cost* is under $25.00 including power supplies.

    With that being said, most embedded developers do the bulk of their work in C and on occasion C++ (with great care), with very little assembly support. For what it's worth, most CPU developers are aware of the transition to C and have done an excellent job of making it possible to do almost all system management, including exceptions/faults/priority/interrupts, in C with very little ASM. Where ASM does become necessary, it's usually expressed in a function-call form that keeps the C code neat and clean.

  183. Re:11k Is Too Big? by Obyron · · Score: 1

    You must be new here. Car analogies can only be used on Slashdot when they are totally flawed for explaining the topic at hand. Your apt, informative car analogy is a violation of Slashdot's cultural mores.

    --
    --Obyron
  184. Interesting, but ... by bkeahl · · Score: 1

    It is a flaw (including libc), but the fact is, we very seldom are going to create programs that aren't going to require the inclusion anyway.

    I'll admit it is embarrassing because of the historical efficiency of 'C', but a program that prints a simple message or exits with an error code is not a real-world application nor a real indicator of how efficient the language is for actual application development.

    It is a good for a yuck though.

  185. 6 bytes ! Beat that !!! by bendelo · · Score: 1

    Yours does more than the article did. Yours actually prints hello world. Hers just returned 42. So I am sure you can do even better...

    If it just has to return 42...

    C:\>debug
    -a 0100
    0D3D:0100 MOV AH,4C
    0D3D:0102 MOV AL,2A
    0D3D:0104 INT 21
    0D3D:0106
    -rcx
    CX 0000
    :6
    -n ben.com
    -w
    Writing 00006 bytes

    -q

    C:\>BEN.COM

    C:\>echo %ERRORLEVEL%
    42

  186. Re:11k Is Too Big? by nsaspook · · Score: 1

    ...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.

    The PIC micro-controller pic18F series and above have several nice C language tools that make embedded programming pretty nice.

    My off-grid solar battery energy storage monitor using a pic18f8722 controller.
    http://www.flickr.com/video_download.gne?id=4252648643

    Early build construction slide-show.
    http://www.flickr.com/photos/nsaspook/sets/72157622934371746/show/

    --
    In GOD we trust, all others we monitor.
  187. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    It does make you wonder though. It added ~11k to the simplest of programs. Where else is it tacking extra junk in?

    People really expect their linkers to do wizard things. Yet they are still pretty simple things. They are general tools that do what we need pretty well. But when you see this you scratch your head and say 'hmm maybe it could do better'. That program should have been emited from the compiler should have been no more than 200-300 bytes. Instead it was nearly 11k... Even with O3 and a few of the tweaker options she was getting about 2k and that was before resorting to asm.

    People also expect wizard things from the O3 switch and a few other ones. They do quite a bit. But not nearly what the magic everyone thinks happens. With some compilers you can have an if(0) {...} block of code and the compiler will dutifully still include the branch and the code in. Some are smarter than that. But do you *really* know unless you look? How many people actually look or just assume? Then you have the other group saying O/arch switches are useless and dont do anything when that is false. They dont do much but they do help and in some cases quite a bit. Then you have another group that is afraid of the O switch saying it emits bad code. The number of times I have seen that in 20 years I can count on 1 hand and it is usually fixed in the next point release.

    With your 'who cares' attitude. Code will get worse.

  188. !baremetal by jjohn · · Score: 1

    "the days of programming bare-metal on DOS"

    If you're using DOS, that's not baremetal.

    1. Re:!baremetal by geekoid · · Score: 1

      I read that and could not decide what was worse. Someone who just said that to look like they know what they are talking about, or someone who used DOS and actually thinks they where 'baremetal'.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  189. Re:11k Is Too Big? by Anonymous Coward · · Score: 1, Interesting

    Actually, embedded software probably makes up the VAST majority of the entire software market. Microcontrollers are everywhere, in your TV, your microwave, dozens in your car, your watch, your phone, your electric razor, everywhere.

  190. Next up by geekoid · · Score: 1

    MIT students try to teach your grandmother to suck eggs.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  191. Re:11k Is Too Big? by makomk · · Score: 1

    This was on an x86 (a pentium 4), so my guess is that Linux no longer ignores some of the bits that the author claims that are ignored, which is why I mentioned the distribution and kernel version.

    Depends on which x86 processor. Apparently, some Pentium 4s have the NX bit and can mark pages as readable but not executable, whereas others don't.

  192. Re:11k Is Too Big? by waveclaw · · Score: 1
    Well, if you read the teensy article you see that normal ELF programs are like your normal car, with an ignition, etc.

    The really small Linux programs are less like a normal car and more like a Service Car. These Service cars start with a pull cord like a lawn mower, no ignition needed. Both are niche items with practical justifications for their creation that owe their current existence to labors of love (one of parts the other of publishing.)

    These cars also use a handlebar instead of a wheel and double as a trailer when being pulled. So, perhaps not unlike the typical Linux application at all.

    --

    "You cannot have a General Will unless you have shared experiences. You cannot be fair to people you don't know."
  193. Re:11k Is Too Big? by npsimons · · Score: 1

    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.

    Not to mention that I have yet to meet the programmer, embedded or otherwise, that can beat the compiler when it comes to optimizing, for space or for speed. Even for my bread and butter, embedded systems, I have yet to have to touch assembler or microcode. Everything is in C and C++. Granted, most of my "embedded" systems are more comparable to desktop powerhouses of 5-10 years ago. But even when a friend and I were making software for an HC11 (where we had to make our own pseudo-filesystem that had to find the sweet spot between reducing writes to flash memory and trying to protect privacy), we wrote everything in C. We just wrote it *smartly* and used good algorithms. The result: entirely readable *and* efficient code. The simple fact of the matter is that unless someone is *hyper* competent and *extremely* familiar with the underlying architecture, they will most likely not beat the compiler for optimizing. If they claim that the higher level language adds too much bloat (such as C of all things!), then they are probably just not qualified to design algorithms or program in the higher level language.

  194. Re:11k Is Too Big? by npsimons · · Score: 1

    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.

    If a programmer doesn't know this, they aren't competent to be programming, much less programming in spaces that may be critical (such as embedded). Don't use wizard code you don't understand. And it's "crt1.o", BTW.

  195. Re:11k Is Too Big? by jc42 · · Score: 1

    The code you have provided a link to will not run on Windows 9.

    Yeah, and this gets to the point of my basic criticism: Writing the program in a different language is not an example of a simpler version of the program "in C" (as was advertised).

    Criticising C because its object files are larger than carefully-tailored assembly code isn't a relevant criticism. C wasn't designed to produce the world's most compact object files. It was designed (look it up) to produce reasonably small programs that are reasonably portable.

    That portability part is extremely important; it was why the language came into existence in the first place. K&R (and friends) at Bell Labs had written most of their first version of unix in assembly language. Then they got a better machine, and wanted it there. They faced a huge rewrite job. They decided that they wanted to do this only once more, so they would do most of the rewrite in a higher-level language. They had the B language, which was fairly good for doing the low-level things needed in an OS kernel, and as they went, they modified it so that they could rewrite more of the kernel in what they finally renamed "C" (because it had become a somewhat different language than B).

    They admitted right from the start that C didn't produce code quite as compact or fast as they could write in assembly. But they decided that it was a worthwhile tradeoff, because new machines were coming along eery few months, and they got quick porting from this new higher-level language.

    So saying that we can do better (i.e., smaller and faster) in assembly isn't very interesting. We've known that since the 1950s when the first "higher-level" languages were developed. Proudly announcing the fact now is just silly, and makes you look like some sort of idiot.

    Comparing the results of different compilers and/or runtime libraries is a lot more interesting. Smaller and/or faster code is interesting and useful. But it's only one of the criteria for "good" code. Telling people how to minimize the size or maximize the speed of code in language X is useful for people using X. But saying "rewrite it in assembly language" is mostly just silly. Most of us know that, and we're not gonna do it very often, because it violates most of our other criteria for the code we're writing.

    (Lately I've been writing a lot of code in perl, python, and other language that are a lot bigger and slower than C. There are often good reasons for doing this. Sometimes I give up and redo something in C for performance reasons. This article does nothing to teach me about doing that better. It's been many years since I've had a valid reason to rewrite something in assembly language. Portability is always more important than what assembly would give me. But YMMV, of course.)

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  196. Ultimate article summary by dazedNconfuzed · · Score: 1

    To make the C program which displays "Hello, world!" smaller, don't display "Hello, world!" and use a different language.

    I appreciate the obsessiveness, but it kinda misses the point.

    --
    Can we get a "-1 Wrong" moderation option?
  197. Re:11k Is Too Big? by steelfood · · Score: 1

    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.

    To be fair, you have to be really damn good to write software for embedded systems, while you just have to be OK to write normal software. Hell, you don't even have to be OK; just read some of the crap in The Daily WTF.

    Which does, in fact, put them a cut above most, but not all, programmers that develop in a higher-level language. And I say most because there probably are programmers that are even better developing in a high level language than embedded systems programmers, simply because the complexity actually increases with the increase in expectation that comes with coding in a high-level language. It's one thing to employ tricks to make something small and fast. It's quite another thing to employ the right tricks towards the same goal, but keep everything organized, readable, and maintainable.

    So don't feel too jilted.

    --
    "If a nation expects to be ignorant and free in a state of civilization, it expects what never was and never will be."
  198. Re:11k Is Too Big? by jc42 · · Score: 1

    Hmmm ... It looks like I should have hit Preview once more. ;-)

    Funny thing is that my last Preview didn't have that problem with the runaway <b> tag. I went to the end of the text and added a bit more text, which should have been in the non-bold part, and hit Submit. Then I noticed what had gone wrong.

    I wonder if I accidentally fat-fingered something that somehow edited a remote part of the textarea window. Or maybe it's just another of the many weirdnesses in Slashcode 2. I have seen it get very confused when I try some rather simple HTML tricks. But a </b> tag seems too innocuous to screw up. Oh well, guess I'll never know.

    OK; that looks good, so I'll hit Submit ...

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
  199. You're forgetting the attribute bytes! by Terje+Mathisen · · Score: 1

    The real code needed a tiny loop to load bytes and write words, something like this:

    ; DS:DI -> Message to write
    ; CX = length of the message
    ; ES:DI -> 0B800h:0 (or any other screen offset)
    ; AH = 8 (or some other reasonable attribute)

    next:
        lodsb
        stosw
        loop next

    Terje

    --
    "almost all programming can be viewed as an exercise in caching"
    1. Re:You're forgetting the attribute bytes! by mandelbr0t · · Score: 1

      Oops. Thanks for that.

      --
      "Please describe the scientific nature of the 'whammy'" - Agent Scully
  200. 100 bytes for Tetris by Anonymous Coward · · Score: 0

    I remember a simplified Tetris clone on DOS that took exactly 100 bytes. It ran in text mode, with the drawing ASCII characters (i.e., ANSI-art style).

    tmegapscm

  201. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    In Soviet Russia, Windows throws out YOUR LAPTOP!!

  202. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    Sure, and where, other than a VIC-20 will that 4K program run?

    Nowhere.

  203. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    To put this in even more perspective, DOS .com files have no header whatsoever. It literally just loads the file in memory at segment boundary + 0x100 (remember, it's 16-bit Intel architecture in all its glory) and jumps to the first byte of that. The extra 0x100 bytes are for OS runtime header for the application.

    The result is that not only you have no relocation, but the size of the binary is limited to 0xFFFF-0x0100 bytes.

    But, hey, it's simple.

  204. Embedded vs non-embedded by rclandrum · · Score: 1

    The fundamental difference between embedded software development and developing applications for PCs is this: embedded software can have no bugs. Unless the device has built-in flash or other mechanisms for upgrading, you absolutely, positively must have the software perfect before the device ships, cuz there ain't gonna be a version 2.0. In embedded software, it is the code that brings the hardware to life, and any bug effectively kills it. When a 3-year accidentally presses the "talk" and "burp" buttons at the same time on her Suzy Flatulence doll and it bursts into flames, not only are you totally fired for not properly safety-testing your code, but the company that you used to work for is totally hosed, along with all your coworkers - and of course all the crispy kids that owned the flaming Suzy dolls.

    Or ask any owner of a car that has a drive-by-wire accelerator whether they think a bug or two is OK.

    Sure, PC application programmers can worry about bugs, but they know that deep down, if there's something wrong with the hyperlink resolution code in their browser app, that they will probably get a chance to fix it. Not so with their embedded developer brothers - when one of *their* products ship, it's usually a scrotum-tightening, make-or-break deal.

    And that's why I'll hire an embedded systems programmer over a .NET GUI weenie any day.

  205. Brings back memories of TSR development by seeks2know · · Score: 1

    Back in the old days, I recall writing TSR (terminate and stay resident) DOS programs in Assembly language. The code needed to be very tight to fit into a PC's teeny RAM (64K system total?) Great learning experience, but the ROI on time invested, unthinkable today.

  206. Re:Apple defines system call APIs at the top of li by Rockoon · · Score: 1

    Hate to break it to ya, but many C compilers dont use compatible ABI's.

    If you've been in the Linux world for awhile, then you might know that Intel's C compiler (and anything it produced) wasnt compatible with GCC until version 10 or so.. so yeah.. about that standard library sharing...

    In the Windows world, C compilers default to CDECL but the standard API calling convention is STDCALL.

    Why do C compilers on windows default to something that isnt the standard for the platform? Its because the C standard library has a couple functions which require a CDECL or a CDECL-like calling convention in order to work, such as printf() .. and this is why the C standard library is an outrageously terrible interface to the OS: it dictates what features the calling convention must support, instead of the OS dictating what the convention will be.

    --
    "His name was James Damore."
  207. Re:11k Is Too Big? by EkriirkE · · Score: 1

    Your soldering iron, power supply, battery charger have computers in them? Must be pretty advanced. All of these usually just have some kind of comparator inside and basic logic ICs - unless they have menus with settings, etc

    --
    from 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
    to 45 2F 6E 40 3C DF 10 71 4E 41 DF AA 25 7D 31 3F
  208. Re:11k Is Too Big? by tomhudson · · Score: 1
    Since you're using Borland:

    1. run w8loss.exe against your executable to strip it. (I just love that name :-)

    2. recompiling using the tiny memory model, shouldn't you call it hello.com?

  209. write 800 lines of assembly by josepha48 · · Score: 1
    to optimise your output file.

    Oh, this isn't C it's assembly, so the title of this thread is all off. It should be how to rewrite your C code in assembly to optimise your code.

    --

    Only 'flamers' flame!
    Does slashdot hate my posts?

  210. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    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.

    No, a better car analogy would replace the output of "Hello World!" with having the car's headlights turn on.

    An old timer would likely just hop in the car and turn on the headlight switch.

    A newer car user would hop in car, insert and turn key to start engine (and all that that involves), then apply the brakes to shift to drive. The car's computer would then automatically turn on the day time running lights. But, on some models, the running lights are not the headlights, but are the turn signals, so the "headlights" output would be in orange instead of 3100k white.

  211. Re:11k Is Too Big? by Yvan256 · · Score: 1

    Unfortunately, the two opcodes were as follow: 0 = No Operation 1 = Shutdown

  212. Re:29 bytes ! Beat that !!! - Easy : 20-21 bytes. by Anonymous Coward · · Score: 0

    Well, you can shave off 2 or 3 bytes by using "int 20" instead of "mov ah, 4C / int 21"
    You can save a few more bytes by using the function 9 of int 21 routine too since it has a simpler calling convention.
    From memory (it's been a while) I think it's only ah=9, and dx=offset. The downside is you have to terminate the string with a '$' sign.
    So the correct shortest Hello World! is:
    c:\ xxx>debug
    -a
    mov ah, 9
    mov dx, 109
    int 21
    int 20
    -f 109 "Hello World!$"
    -r cx :0015
    -n c:\ xxx\ hello.com
    -w
    -q

    That should shave off a nice 8 bytes which you can use elsewhere :p
    You can even shave off one more byte if you use the fact that on the stack is the return address 0000, which is the start of some program data block which conveniently starts with "int 20", hence your program can use the 1 byte "ret" instead of the 2-byte "int 20" - but that's kinda hacky.

  213. OMG It's a PIG by Well-Fed+Troll · · Score: 1

    He's right, you forgot to mention that is has TWICE as much EPROM memory, positively cavernous at 512 12-bit words.

    (heh those chips bring back memories, way back in 97 I used to use the a lot of those Microchip parts 16c, 18c, 17c etc families)

  214. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    it is not fine that it imports every module in the library when I am static linking.

    It doesn't. It imports the modules you reference. You do realise that a static library is nothing more than an archive of object files? Read the man page for 'ar'

  215. 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.
  216. Re:11k Is Too Big? by Anonymous+Brave+Guy · · Score: 1

    Sure, the hello.com example is obviously the trivial case, but the same sorts of bloat it demonstrates apply all too easily on larger scales as well.

    I am currently running 47 processes on my WinXP box. Those include:

    • a tool that draws simple things like a clock or the title of the track I'm playing in Media Player on the LCD display on my keyboard (14MB)
    • an e-mail client (50MB)
    • a web browser with half a dozen tabs open on simple pages like Slashdot (137MB)
    • various completely idle server daemons (MySQL, Apache, SVN, etc.) (10–20MB each)
    • a souped up task manager utility (33MB)
    • multiple processes to support my many-buttoned Logitech mouse (total about 18MB)
    • an audio control panel for my sound card (24MB).

    The list goes on, but you get the point. It is crazy that such simple applications should take multi-megabyte footprints (and those are the working sets I'm talking about, not all the stuff that's paged out).

    Does this matter? Well, yes, when all the trivial background stuff adds up to nearly 1GB of RAM. That is significant even on today's PCs, if you want to run an application like a high-end game or graphics package that actually needs a lot of RAM to hold the data to do its job. And of course, the more you load up and possibly page out, the slower the system boots and applications load, the less effective caches become, etc., so there is a performance hit as well.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  217. Pretty Fat by thethibs · · Score: 1

    That initial 11kB is pretty fat. MarcsForth, a bloated version of Forth 83 without any attempt at optimization uses 11.1kB (including the word headers, which is like keeping the whole symbol table in the executable). On the other hand, the reference manual tips the scales at 310kB.

    Just as interesting: it was finished in 1987 and runs without a glitch under Windows XP.

    --
    I'm a Programmer. That's one level above Software Engineer and one level below Engineer.
  218. Re:11k Is Too Big? by innocent_white_lamb · · Score: 1

    run w8loss.exe against your executable to strip it.
     
    w8loss.exe doesn't come with Turbo C, at least not with the version that I have here.
     
      recompiling using the tiny memory model, shouldn't you call it hello.com?
     
    I kind of thought so too, but the compiler named the executable hello.exe.

    --
    If you're a zombie and you know it, bite your friend!
  219. Real (time) programmers by thethibs · · Score: 1

    The folk who do embedded code can easily do the high level stuff; the converse is not true.

    The one problem with programmers who've been working close to the metal is that when they do have something to do at a high level (in bash, for instance) they tend to spend too much time getting it just right.

    --
    I'm a Programmer. That's one level above Software Engineer and one level below Engineer.
  220. Big letdown, was hoping for shorter Hello World by noidentity · · Score: 1

    It was a big letdown finding out this wasn't the final optimization to Hello World, transforming it from a junky affair of #include and printf (or puts) into a highly-refined program of half the source text. The headline really had me rekindling my youthful yearning for a smaller Hello World. I am so let down right now. I'm calling a friend.

  221. Re:11k Is Too Big? by azmodean+1 · · Score: 1

    True, but that's no excuse for a compiler/linker to bring in a library that's not needed.

    I'm on the fence about this. For the VAST majority of uses of gcc, you are going to want to include stdlib and friends, and for the other uses, there's a flag to disable it. Now there does not seem to be a way to generate mind-bendingly small executables with gcc, but I'm unconvinced of the need for that either :P

    On second thought, I think gcc-arm will probably generate super-tiny executables with the proper flags, it just won't run on x86 linux...

    So anyway, the common use-case is x86 system with full-sized linux system, for which the common use case is programs that will want to use stdlib stuff.

  222. Where's the x86_64 port? by rwa2 · · Score: 1

    To all you people complaining about the original article being old news from 1999... port it to a modern 64-bit architecture!

    Needs a newer nasm or yasm:
    http://www.tortall.net/projects/yasm/wiki/AMD64

    Of course, to win the game, you'd probably want to go the other way and backport it to a 16-bit or 8-bit processor.

    Anyway, loved the article... I didn't like the way most CS classes glossed over these kinds of admittedly mundane but practical matters. I am interested in knowing what every single last damn byte is doing there!

  223. Re:11k Is Too Big? by techno-vampire · · Score: 1
    I'm on the fence about this. For the VAST majority of uses of gcc, you are going to want to include stdlib and friends, and for the other uses, there's a flag to disable it.

    If gcc needed to be as samll and compact as possible, that would be a good way to handle this. However, that's not true, and I see no reason it shouldn't check to see if libc is needed and link it in if, and only if it's going to be used, just as it does with every other library.

    --
    Good, inexpensive web hosting
  224. Re:11k Is Too Big? by Bootarn · · Score: 1

    Tell me about it. I've been playing around with PICs lately and I've recently compared a compiled C program (mikroC) to a program that I wrote myself in assembler. Its task was simply to output "Hello World!" to a HD44780 LCD module, and whereas I could suffice with about 20-30 lines of code, whereas the compiled program required about 120 lines to do exactly the same thing!

    The compiler created about 10 subroutines out of thin air. It was a mess!

  225. Re:Apple defines system call APIs at the top of li by azmodean+1 · · Score: 1

    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.

    This is a strawman, there are various approaches to this problem that do not involve locking down access to system calls to a single channel. You also make several incorrect (or at least incomplete) assumptions about the alternatives.
    1. The USER must re-compile software if the OS changes.
            This is not true, in the Linux and BSD worlds, the majority of the compilation happens at the distribution level, end users generally don't mess with it unless they WANT to. Additionally the provider of the software can compile the software, though admittedly this is difficult if your project targets many environments.
    2. Commercial software requires binary compatibility across OS versions because it can't be rebuilt.
          This is a false dilemma, see below points.
          2a. Commercial software must be compiled by the authoring organization.
                    There are commercial software suites that provide source to customers, it is only the massive level of paranoia about preserving their "precious IP resources" software houses have that keeps this from being more common. It is something THEY want, not the customer, so why should the customer end up paying for it? (and this does not mean that the user MUST be the one to re-compile, an intermediary of some kind could just as well do it.)
          2b. The authoring organization can not recompile and redistribute software if the OS breaks binary compatibility.
                      Linux and BSD distributions do it, and they aren't "real professionals" right? In my experience the only reason commercial software houses can't handle it is because their development methodology is deeply broken and can only be coaxed to work properly for a short time around a launch window. In other words, the inability to provide deliverables that will work on multiple platforms is another self-inflicted problem, once again, the end user should not have to pay for this.

    You have some valid points, and I think locking down libc as being essentially part of the OS is one solution (hell, it's come up on lkml from time to time), but I think you vastly overstate your position.

  226. Re:11k Is Too Big? by tomhudson · · Score: 1

    w8loss.exe shipped with various Borland products. I know it came with BC++3.1 (which I upgraded to from Turbo C 1.0) and Delphi. If you have either of those, you should have a copy.

    A few years after I bought Delphi 1.0 ($500) Borland allowed it to be released as a cover disk as part of an effort to generate buzz for a later version.

    Delphi 1.0 was on a cover CD for the December 1997 issue of the UK magazine PCW, with upgrade offers; Delphi 2.0 was on a cover CD for the May 1999 issue of the UK magazine PCW, with upgrade offers; Delphi 3.0 was remaindered by Inprise UK in September 1998; I have used it. both for GUI and console mode programs; Delphi 7.0 was current; as was a version for LINUX.

    It *might* also be sitting in a kylix distribution (oh, the pain).

  227. Re:The point of hello world is to print hello worl by ArsenneLupin · · Score: 1

    Actually, I believe the point is to print "hello, world".

    Actually, her point was to just return an exit status of 42.

    However, if you really want to see hello world, add 37 bytes, and use this.

  228. Re:11k Is Too Big? by SharpFang · · Score: 1

    Yes... but you surely realize that embedded C for microcontroller is significantly different from most "high level" languages?

    Imagine a seasoned Enterprise Java developer switching to the required mindset...

    --
    45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
  229. Re:The point of hello world is to print hello worl by BarryNorton · · Score: 1

    No, I still want to see 'hello, world'. Your link doesn't have it right either.

  230. Re:The point of hello world is to print hello worl by ArsenneLupin · · Score: 1

    No, I still want to see 'hello, world'. Your link doesn't have it right either.

    So, what exactly is wrong?

  231. Re:11k Is Too Big? by Raptor851 · · Score: 1

    and a modern PC it doesn't matter at all.

    This is EXACTLY why we have to constantly buy new hardware, and upgrade the CPU/RAM to do the same exact tasks were were doing with 1/100 the power 5 years ago....

  232. To reply to your specific points... by tlambert · · Score: 1

    To reply to your specific points...

    I'm going to paraphrase for brevity; forgive me and correct me if I misrepresent your points:

    (1) The majority of compilation happens at the distribution level

    I think this is addressed by my point about whether or not your platform has a lot of commercial software, or not. Commercial software comes from a huge variety of vendors, not a single vendor. In the "BSD distribution" or "Linux distribution" model, yes, the distributor will likely be compiling up all the packages they can possibly make work. The problem with this is that the vast majority of these are not going to be commercial packages.

    You can maybe argue that commercial software doesn't have value to you, but that is simply not true for the majority of computer users. It's almost universally true for non-technical computer users, or you would be seeing greater desktop penetration of a BSD or Linux distribution, and some hardware vendor wanting to drive down either their COGS (Cost Of Goods Sold), to increase their profit margin, or to lower their price point. Other than a few luke-warm toe dipping by a couple of vendors who have not followed through with jumping into the water wholesale, this simply hasn't happened.

    (2)(a) Commercial software could provide source code, but does not because of paranoia

    This is false. Commercial software exists because there are margins in it. I've been in commercial software since the 1980's. Source code has always been available for a price, it's just not a price the market will bear. I've been party to a large number of contracts, such as my company being a designated vendor for AFCAC (Air Force Computer Acquisition Center) contract 451, where source escrow was a requirement. Source escrow is surprisingly easy and cheap to add to contracts between vendors and end user organizations.

    The other factor here is that a vendor can not trust a third party to do the necessary due diligence with regard to compiling other code correctly, or testing it to make sure it meets specification. It can't trust that there will be timely security and other updates to the software when the vendor mandates them. It can't trust that the third party will have the necessary capitol resources, such as machine rooms full of machines, necessary for long term testing for the software and hardware combinations they intend to release on.

    Again, you can maybe argue that if the vendor did test automation development at an order of magnitude higher than most vendors currently do (with the associated increase in cost to the consumer), that they could provide the necessary testing resources. And you could argue that mandating ISO 9001 certification for the third party, and doing compliance audits to make sure that the quality assurance model isn't breaking down anywhere, could cover the potential quality issues for the third party on which the vendor is taking their reputation. The costs involved would drive the software costs to the consumer far higher than single-source. This would not only put the vendor at a competitive disadvantage with regard to other vendors, it would fail to address the increased latency in the supply chain for things patches for zero-day exploits.

    (2)(b) Binary compatibility issues can be addressed by recompilation if commercial software houses just fixed their methodology

    With respect, I disagree. I addressed the process latency issue and affirmative quality requirements in my response to (2)(a), above, so I won't repeat myself on those points.

    In regard to "fixing the development methodology" to enable supporting multiple platforms (and I take that to mean incompatible versions of the same platform, not just cross-platform), you're wrong. Correct software development methodology in that environment requires that you establish interface contracts between components and software, such that recompilation is easily accomplished.

    No one in the Open Source world is willing to do this to any approximation of the r

  233. Re:11k Is Too Big? by Anonymous Coward · · Score: 0

    it has to do with people generally not caring about 11k.

    Um, isn't that exactly what bloat is? "Who cares if it's n bytes, it works!"

  234. Re:11k Is Too Big? by rew · · Score: 1

    Oh, you care about disk space? Ah! Indeed I don't... :-)

    Disk space is some 100 times cheaper than RAM. It's the bloat that ends up in RAM that means you have to buy 2G or 4G of ram in a modern machine to make it work. I can still make a (server-) install in under 1G of disk space, but running a desktop in under 1G of RAM is a performance problem.

    That's the bloat I care about.

  235. Re:11k Is Too Big? by npsimons · · Score: 1

    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.

    If a programmer doesn't know this, they aren't competent to be programming, much less programming in spaces that may be critical (such as embedded). Don't use wizard code you don't understand. And it's "crt1.o", BTW.

    Let me follow this up by saying that I don't want to discourage anyone from /learning/ how to program, especially the GP, as he or she seems interested enough in it to search out things like this. What I mean by "they aren't competent to be programming" is that until someone is familiar enough with the language and underlying hardware and software, they shouldn't try to pass off their programs as the most reliable or efficient things around. Things like the The Pragmatic Programmer are especially cogent to becoming a better programmer, even if you only take away this one lesson: understand the abstractions you use. The layers of computing have been built and tested for decades, and most of the time they make sense and make your life easier (that's what they are *for*). But make sure you at least use them properly, and the surest way to make sure you use them properly is to *understand* them, eg, know that GCC will attach a whole bunch of stuff to your program (because almost all programs use it) that you might not need.

  236. Amazing news? by codewyrds · · Score: 1

    http://www.google.com/search?q=minimize+exe+size - a mere 1/2 million hits? An Anonymous Coward, indeed :) It's good to see Linux catching up; to think, PE executables are... PE executables!

    What has been will be again, what has been done will be done again; there is nothing new under the sun

  237. Re:11k Is Too Big? by BitZtream · · Score: 1

    Theres no reason perl or C# couldn't be used on those devices. The language doesn't define how much resources it requires, its just a way to describe what you want do so that it can be translated to something the CPU can actually understand. I most certainly can use C# on my phone. Its one of the preferred languages for WinMo, and mono lets me compile to a static binary for things like the iPhone which don't allow for dynamic runtimes.

    The problem with higher level languages is that the compilers and VMs for them are rather shitty at optimizing things, which is fine where they are used as they aren't used for performance related bits nor are they used on light weight hardware.

    If someone wanted to bother investing the time into making a extremely intelligent compiler it might change.

    It won't happen because the people capable writing code of the quality needed on these devices prefer to work in assembly so they have total control and know exactly whats being done.

    --
    Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  238. Re:11k Is Too Big? by SharpFang · · Score: 1

    Are you absolutely sure Perl is the right language for a car alarm remote, which has 4KB of Flash, 128 bytes of RAM and a 1MHz clock, and uses that for bit-banging a bidirectional radio, encryption, authentication, and power management by reducing the system clock to 4Hz when idle?

    --
    45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
  239. and in the right corner by shnull · · Score: 1

    weighing in at 179kb, it's Hello World, the sequel http://www.pouet.net/prod.php?which=30244

    --
    beware he who denies you access to information for in his mind, he already deems himself to be your master (SMAC-ish)
  240. Re:11k Is Too Big? by Kashgarinn · · Score: 1

    I had to learn programming on a computer with only 1 bit of memory

    You lucky, lucky bastard..

    I had to learn on a computer with N O Memory, instead it had a rotating sawblade you had to etch your bits into, while moving!

  241. Not asking for libc by jgrahn · · Score: 1

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

    Shouldn't come as a surprise. C has a runtime, like most other languages. -- But really, this was a good article. Looking under the hood and finding the few things that are there is very instructive.

  242. Re:29 bytes ! Beat that !!! - Easy : 20-21 bytes. by Anonymous Coward · · Score: 0

    -f 109 "Hello World!$"
    -r cx :0015

    Looks like a counting fail or else you left out the $ to save space. :P. "Hello" and "World" are five bytes each, plus three bytes for the space, exclamation point, and dollar sign. 5 + 5 + 3 + 9 = 22 = 0x16, not 0x15, according to my math.

  243. 11k ? For reference... by fyngyrz · · Score: 1

    11k... that's really kind of apalling when I stop and think about it.

    ...a "hello world" program under TSC's 6800 or 6809 Flex is 23 bytes . Just wrote one and assembled it to be certain:

    | LIB FEQUATES
    | ORG $C100
    |X FCC "hello world",$D,$A,$4
    |ST LDX #X
    | JSR PSTRNG
    | JMP WARMS
    | END ST

    There's no question that a certain economy of implementation has been lost.

    --
    I've fallen off your lawn, and I can't get up.