Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Simpler "Hello World" Demonstrated In C

kdawson posted more than 4 years ago | from the non-obfuscated dept.

Programming 582

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

cancel ×

582 comments

Sorry! There are no comments related to the filter you selected.

BTDT (2, Insightful)

argent (18001) | more than 4 years ago | (#31504044)

*sigh*

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

Re:BTDT (1)

MichaelSmith (789609) | more than 4 years ago | (#31504090)

*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 ;)

Re:BTDT (2, Informative)

maxume (22995) | more than 4 years ago | (#31504122)

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

Re:BTDT (1)

ground.zero.612 (1563557) | more than 4 years ago | (#31504342)

I actually RTFA too, but I didn't see mention of the TA's workstation's model "Deep Thunk." I'm going to have to examine my security measures and shutdown my Gmail account, because I think the Chinese have hacked it and knocked off my Douglas Adam's inspired "Deep Thought" workstation. On which I've obviously optimized TA's code down to the proper 42 bytes.

Re:BTDT (-1, Troll)

Anonymous Coward | more than 4 years ago | (#31504382)

It was only submitted because the author has a vagina between her legs, and geeks go ga-ga over anybody with a cunt. The author has been identified as the sitting cumdumpster on the far left of this [ksplice.com] picture.

I knew her when she went to high school. She was popular for taking random dudes into her daddy's bedroom, unzipping their flys, and fellating them through their still-buttoned pants! She has a distinctive giggle that was often muffled from the come in her mouth and on her lips. She also liked to wear her shirts all day, especially if they were stained with her partners' jissom.

Daddy: " What's that all over your chest, Jessie? "
Jessica: " It's, um, glue from my popsicle-stick project. Hnnhnnhnnhnnhnnheehee! "
Daddy: " Aww, how cute. You're so adorable, precious "

Re:BTDT (-1, Troll)

Anonymous Coward | more than 4 years ago | (#31504422)

Christ, what an asshole.

Re:BTDT (0)

Anonymous Coward | more than 4 years ago | (#31504498)

You so obviously didn't get any.

Re:BTDT (5, Insightful)

tomhudson (43916) | more than 4 years ago | (#31504516)

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 [ksplice.com] - 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 [ksplice.com] , which I derided in this comment [ksplice.com] :

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.

Your official guide to the Jigaboo presidency (-1, Troll)

Anonymous Coward | more than 4 years ago | (#31504050)

Congratulations on your purchase of a brand new nigger! If handled properly, your apeman will give years of valuable, if reluctant, service.

INSTALLING YOUR NIGGER.
You should install your nigger differently according to whether you have purchased the field or house model. Field niggers work best in a serial configuration, i.e. chained together. Chain your nigger to another nigger immediately after unpacking it, and don't even think about taking that chain off, ever. Many niggers start singing as soon as you put a chain on them. This habit can usually be thrashed out of them if nipped in the bud. House niggers work best as standalone units, but should be hobbled or hamstrung to prevent attempts at escape. At this stage, your nigger can also be given a name. Most owners use the same names over and over, since niggers become confused by too much data. Rufus, Rastus, Remus, Toby, Carslisle, Carlton, Hey-You!-Yes-you!, Yeller, Blackstar, and Sambo are all effective names for your new buck nigger. If your nigger is a ho, it should be called Latrelle, L'Tanya, or Jemima. Some owners call their nigger hoes Latrine for a joke. Pearl, Blossom, and Ivory are also righteous names for nigger hoes. These names go straight over your nigger's head, by the way.

CONFIGURING YOUR NIGGER
Owing to a design error, your nigger comes equipped with a tongue and vocal chords. Most niggers can master only a few basic human phrases with this apparatus - "muh dick" being the most popular. However, others make barking, yelping, yapping noises and appear to be in some pain, so you should probably call a vet and have him remove your nigger's tongue. Once de-tongued your nigger will be a lot happier - at least, you won't hear it complaining anywhere near as much. Niggers have nothing interesting to say, anyway. Many owners also castrate their niggers for health reasons (yours, mine, and that of women, not the nigger's). This is strongly recommended, and frankly, it's a mystery why this is not done on the boat

HOUSING YOUR NIGGER.
Your nigger can be accommodated in cages with stout iron bars. Make sure, however, that the bars are wide enough to push pieces of nigger food through. The rule of thumb is, four niggers per square yard of cage. So a fifteen foot by thirty foot nigger cage can accommodate two hundred niggers. You can site a nigger cage anywhere, even on soft ground. Don't worry about your nigger fashioning makeshift shovels out of odd pieces of wood and digging an escape tunnel under the bars of the cage. Niggers never invented the shovel before and they're not about to now. In any case, your nigger is certainly too lazy to attempt escape. As long as the free food holds out, your nigger is living better than it did in Africa, so it will stay put. Buck niggers and hoe niggers can be safely accommodated in the same cage, as bucks never attempt sex with black hoes.

FEEDING YOUR NIGGER.
Your Nigger likes fried chicken, corn bread, and watermelon. You should therefore give it none of these things because its lazy ass almost certainly doesn't deserve it. Instead, feed it on porridge with salt, and creek water. Your nigger will supplement its diet with whatever it finds in the fields, other niggers, etc. Experienced nigger owners sometimes push watermelon slices through the bars of the nigger cage at the end of the day as a treat, but only if all niggers have worked well and nothing has been stolen that day. Mike of the Old Ranch Plantation reports that this last one is a killer, since all niggers steal something almost every single day of their lives. He reports he doesn't have to spend much on free watermelon for his niggers as a result. You should never allow your nigger meal breaks while at work, since if it stops work for more than ten minutes it will need to be retrained. You would be surprised how long it takes to teach a nigger to pick cotton. You really would. Coffee beans? Don't ask. You have no idea.

MAKING YOUR NIGGER WORK.
Niggers are very, very averse to work of any kind. The nigger's most prominent anatomical feature, after all, its oversized buttocks, which have evolved to make it more comfortable for your nigger to sit around all day doing nothing for its entire life. Niggers are often good runners, too, to enable them to sprint quickly in the opposite direction if they see work heading their way. The solution to this is to *dupe* your nigger into working. After installation, encourage it towards the cotton field with blows of a wooden club, fence post, baseball bat, etc., and then tell it that all that cotton belongs to a white man, who won't be back until tomorrow. Your nigger will then frantically compete with the other field niggers to steal as much of that cotton as it can before the white man returns. At the end of the day, return your nigger to its cage and laugh at its stupidity, then repeat the same trick every day indefinitely. Your nigger comes equipped with the standard nigger IQ of 75 and a memory to match, so it will forget this trick overnight. Niggers can start work at around 5am. You should then return to bed and come back at around 10am. Your niggers can then work through until around 10pm or whenever the light fades.

ENTERTAINING YOUR NIGGER.
Your nigger enjoys play, like most animals, so you should play with it regularly. A happy smiling nigger works best. Games niggers enjoy include: 1) A good thrashing: every few days, take your nigger's pants down, hang it up by its heels, and have some of your other niggers thrash it with a club or whip. Your nigger will signal its intense enjoyment by shrieking and sobbing. 2) Lynch the nigger: niggers are cheap and there are millions more where yours came from. So every now and then, push the boat out a bit and lynch a nigger.

Lynchings are best done with a rope over the branch of a tree, and niggers just love to be lynched. It makes them feel special. Make your other niggers watch. They'll be so grateful, they'll work harder for a day or two (and then you can lynch another one). 3) Nigger dragging: Tie your nigger by one wrist to the tow bar on the back of suitable vehicle, then drive away at approximately 50mph. Your nigger's shrieks of enjoyment will be heard for miles. It will shriek until it falls apart. To prolong the fun for the nigger, do *NOT* drag him by his feet, as his head comes off too soon. This is painless for the nigger, but spoils the fun. Always wear a seatbelt and never exceed the speed limit. 4) Playing on the PNL: a variation on (2), except you can lynch your nigger out in the fields, thus saving work time. Niggers enjoy this game best if the PNL is operated by a man in a tall white hood. 5) Hunt the nigger: a variation of Hunt the Slipper, but played outdoors, with Dobermans. WARNING: do not let your Dobermans bite a nigger, as they are highly toxic.

DISPOSAL OF DEAD NIGGERS.
Niggers die on average at around 40, which some might say is 40 years too late, but there you go. Most people prefer their niggers dead, in fact. When yours dies, report the license number of the car that did the drive-by shooting of your nigger. The police will collect the nigger and dispose of it for you.

COMMON PROBLEMS WITH NIGGERS - MY NIGGER IS VERY AGGRESIVE
Have it put down, for god's sake. Who needs an uppity nigger? What are we, short of niggers or something?

MY NIGGER KEEPS RAPING WHITE WOMEN
They all do this. Shorten your nigger's chain so it can't reach any white women, and arm heavily any white women who might go near it.

WILL MY NIGGER ATTACK ME?
Not unless it outnumbers you 20 to 1, and even then, it's not likely. If niggers successfully overthrew their owners, they'd have to sort out their own food. This is probably why nigger uprisings were nonexistent (until some fool gave them rights).

MY NIGGER BITCHES ABOUT ITS "RIGHTS" AND "RACISM".
Yeah, well, it would. Tell it to shut the fuck up.

MY NIGGER'S HIDE IS A FUNNY COLOR. - WHAT IS THE CORRECT SHADE FOR A NIGGER?
A nigger's skin is actually more or less transparent. That brown color you can see is the shit your nigger is full of. This is why some models of nigger are sold as "The Shitskin".

MY NIGGER ACTS LIKE A NIGGER, BUT IS WHITE.
What you have there is a "wigger". Rough crowd. WOW!

IS THAT LIKE AN ALBINO? ARE THEY RARE?
They're as common as dog shit and about as valuable. In fact, one of them was President between 1992 and 2000. Put your wigger in a cage with a few hundred genuine niggers and you'll soon find it stops acting like a nigger. However, leave it in the cage and let the niggers dispose of it. The best thing for any wigger is a dose of TNB.

MY NIGGER SMELLS REALLY BAD
And you were expecting what?

SHOULD I STORE MY DEAD NIGGER?
When you came in here, did you see a sign that said "Dead nigger storage"? .That's because there ain't no goddamn sign.

Hello World (0)

Anonymous Coward | more than 4 years ago | (#31504058)

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

Re:Hello World (5, Funny)

Megaweapon (25185) | more than 4 years ago | (#31504084)

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.

Re:Hello World (1, Funny)

Anonymous Coward | more than 4 years ago | (#31504512)

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.

Re:Hello World (0)

Anonymous Coward | more than 4 years ago | (#31504134)

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

Re:Hello World (5, Funny)

thegrassyknowl (762218) | more than 4 years ago | (#31504486)

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

11k Is Too Big? (-1, Offtopic)

WrongSizeGlass (838941) | more than 4 years ago | (#31504060)

An 11k app is not going to make me, or my computer, say 'Good Bye World', so I don't know what the big deal is. "Hello World' != 'Good By Compiler'.

Re:11k Is Too Big? (5, Insightful)

CapnStank (1283176) | more than 4 years ago | (#31504140)

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?

Re:11k Is Too Big? (5, Insightful)

gzipped_tar (1151931) | more than 4 years ago | (#31504326)

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

Re:11k Is Too Big? (4, Insightful)

ucblockhead (63650) | more than 4 years ago | (#31504580)

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.

Re:11k Is Too Big? (5, Insightful)

exasperation (1378979) | more than 4 years ago | (#31504150)

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

Re:11k Is Too Big? (4, Insightful)

jc42 (318812) | more than 4 years ago | (#31504456)

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

Re:11k Is Too Big? (0)

Anonymous Coward | more than 4 years ago | (#31504200)

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

Re:11k Is Too Big? (3, Insightful)

WrongSizeGlass (838941) | more than 4 years ago | (#31504264)

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.

Re:11k Is Too Big? (4, Informative)

Anonymous Coward | more than 4 years ago | (#31504306)

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.

Re:11k Is Too Big? (1)

techno-vampire (666512) | more than 4 years ago | (#31504318)

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.

Re:11k Is Too Big? (1)

bsDaemon (87307) | more than 4 years ago | (#31504460)

otherwise she would have done something like this:

#include

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

Re:11k Is Too Big? (1)

bsDaemon (87307) | more than 4 years ago | (#31504470)

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

Re:11k Is Too Big? (1)

nextekcarl (1402899) | more than 4 years ago | (#31504360)

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

Re:11k Is Too Big? (0)

Rockoon (1252108) | more than 4 years ago | (#31504388)

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.

Re:11k Is Too Big? (2, Informative)

TyFoN (12980) | more than 4 years ago | (#31504440)

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.

Re:11k Is Too Big? (1)

symbolset (646467) | more than 4 years ago | (#31504514)

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 [pcworld.com] 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.

Re:11k Is Too Big? (4, Interesting)

Simonetta (207550) | more than 4 years ago | (#31504336)

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

Re:11k Is Too Big? (2, Funny)

VocationalZero (1306233) | more than 4 years ago | (#31504528)

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

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

Re:11k Is Too Big? (4, Funny)

Zouden (232738) | more than 4 years ago | (#31504596)

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.

Missing the point (5, Funny)

textstring (924171) | more than 4 years ago | (#31504068)

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

So what? (2, Insightful)

Anonymous Coward | more than 4 years ago | (#31504072)

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

Re:So what? (5, Insightful)

AmberBlackCat (829689) | more than 4 years ago | (#31504504)

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.

Old news is VERY OLD (5, Informative)

deblau (68023) | more than 4 years ago | (#31504094)

Re:Old news is VERY OLD (5, Informative)

shird (566377) | more than 4 years ago | (#31504172)

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 [microsoft.com]

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

Re:Old news is VERY OLD (1)

sootman (158191) | more than 4 years ago | (#31504232)

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

Re:Old news is VERY OLD (0)

Anonymous Coward | more than 4 years ago | (#31504346)

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

Re:Old news is VERY OLD (4, Interesting)

Gamma747 (1438537) | more than 4 years ago | (#31504446)

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

Where's the I/O? (0)

Anonymous Coward | more than 4 years ago | (#31504104)

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

Nice but? (4, Insightful)

garcia (6573) | more than 4 years ago | (#31504106)

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?

BASICally she did this (0)

Anonymous Coward | more than 4 years ago | (#31504110)

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

I can code that app in... (5, Funny)

putaro (235078) | more than 4 years ago | (#31504116)

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?

Re:I can code that app in... (1)

Dynetrekk (1607735) | more than 4 years ago | (#31504234)

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?

Re:I can code that app in... (1, Informative)

Anonymous Coward | more than 4 years ago | (#31504358)

Commodore BASIC:

?42

Re:I can code that app in... (2, Informative)

eggled (1135799) | more than 4 years ago | (#31504420)

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

Re:I can code that app in... (1)

i_ate_god (899684) | more than 4 years ago | (#31504520)

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?

Re:I can code that app in... (5, Insightful)

Dynetrekk (1607735) | more than 4 years ago | (#31504552)

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?

Re:I can code that app in... (0)

Anonymous Coward | more than 4 years ago | (#31504524)

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

Thanks! (0)

Anonymous Coward | more than 4 years ago | (#31504132)

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 [uclibc.org] is a godsend.

Umm, but (4, Insightful)

Psychotria (953670) | more than 4 years ago | (#31504136)

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

Re:Umm, but (1)

rotide (1015173) | more than 4 years ago | (#31504178)

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.

Re:Umm, but (0)

Anonymous Coward | more than 4 years ago | (#31504258)

Hmm

Re:Umm, but (2, Informative)

Psychotria (953670) | more than 4 years ago | (#31504278)

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

Re:Umm, but (0)

Anonymous Coward | more than 4 years ago | (#31504384)

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

Re:Umm, but (1)

ralphdaugherty (225648) | more than 4 years ago | (#31504466)

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?

If it's so simple, (4, Insightful)

newcastlejon (1483695) | more than 4 years ago | (#31504146)

Why doesn't it fit in TFS?

Similarly (2, Interesting)

McBeer (714119) | more than 4 years ago | (#31504152)

Awhile back I read another similar article [phreedom.org] . 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.

IEFBR14 (4, Interesting)

kenh (9056) | more than 4 years ago | (#31504158)

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 [wikipedia.org]

Re:IEFBR14 (1)

hudsucker (676767) | more than 4 years ago | (#31504302)

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

Re:IEFBR14 (3, Interesting)

craighansen (744648) | more than 4 years ago | (#31504488)

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

Brian is a funny name for a girl... (0)

Anonymous Coward | more than 4 years ago | (#31504168)

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

Re:Brian is a funny name for a girl... (1)

StillAnonymous (595680) | more than 4 years ago | (#31504398)

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

Simpler "Hello World" in C? (5, Insightful)

kenh (9056) | more than 4 years ago | (#31504204)

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?

Re:Simpler "Hello World" in C? (3, Interesting)

MerlynEmrys67 (583469) | more than 4 years ago | (#31504256)

I always liked the "Strangest Abuse of the Rules" catagory winner for Hello World
char*_="Hello world.\n";

That is it - the whole program.

Re:Simpler "Hello World" in C? (2, Informative)

refactored (260886) | more than 4 years ago | (#31504328)

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!

Re:Simpler "Hello World" in C? (1)

RichMan (8097) | more than 4 years ago | (#31504462)

> 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 [latech.edu]

Re:Simpler "Hello World" in C? (3, Interesting)

onefriedrice (1171917) | more than 4 years ago | (#31504472)

Parent said a lot of words...

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

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

Re:Simpler "Hello World" in C? (0)

Anonymous Coward | more than 4 years ago | (#31504376)

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.

Re:Simpler "Hello World" in C? (-1, Troll)

Anonymous Coward | more than 4 years ago | (#31504416)

There's no such language as assembler GOD DAMN IT! Do you idiots call C "compiler"? No? Good! Now STOP IT!

Still written (mostly) in C. . . (2, Interesting)

JSBiff (87824) | more than 4 years ago | (#31504556)

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

Something similar (2, Interesting)

crow (16139) | more than 4 years ago | (#31504250)

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.

Re:Something similar (1)

arndawg (1468629) | more than 4 years ago | (#31504292)

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?

Re:Something similar (1)

crow (16139) | more than 4 years ago | (#31504542)

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.

GCC... (0)

Anonymous Coward | more than 4 years ago | (#31504254)

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

CDC (1)

Sanat (702) | more than 4 years ago | (#31504266)

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.

One of the first things I did (1)

MpVpRb (1423381) | more than 4 years ago | (#31504280)

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

YES!!!! FINALLY (5, Funny)

commodoresloat (172735) | more than 4 years ago | (#31504284)

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.

Re:YES!!!! FINALLY (1, Funny)

Anonymous Coward | more than 4 years ago | (#31504348)

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

Re:YES!!!! FINALLY (2, Funny)

Aphoxema (1088507) | more than 4 years ago | (#31504402)

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*

In other conspiracy news... (1)

creimer (824291) | more than 4 years ago | (#31504310)

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

Stoner code. (3, Funny)

geekmux (1040042) | more than 4 years ago | (#31504312)

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

Occams Wedge (1)

CODiNE (27417) | more than 4 years ago | (#31504324)

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

Re:Occams Wedge (4, Insightful)

Arker (91948) | more than 4 years ago | (#31504418)

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.

any torrent links? (1, Funny)

SethJohnson (112166) | more than 4 years ago | (#31504334)

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

Seth

C++ is worse (4, Insightful)

MobyDisk (75490) | more than 4 years ago | (#31504340)

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.

Re:C++ is worse (1, Interesting)

Anonymous Coward | more than 4 years ago | (#31504482)

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.

Re:C++ is worse (5, Informative)

macshit (157376) | more than 4 years ago | (#31504490)

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

Ob. quote (1)

gzipped_tar (1151931) | more than 4 years ago | (#31504352)

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

To answer the author's last question... (1)

mark-t (151149) | more than 4 years ago | (#31504374)

scripts. :)

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

The meaning of life, the universe, and everything (1)

Graham J - XVI (1076671) | more than 4 years ago | (#31504436)

...in 45 bytes - Impressive!

OK, now generalize that (2, Insightful)

istartedi (132515) | more than 4 years ago | (#31504442)

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.

Sell your Seagate shares *now* ... (1, Funny)

Anonymous Coward | more than 4 years ago | (#31504450)

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

Ah, hello world. (1)

SomeGuyFromCA (197979) | more than 4 years ago | (#31504522)

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;
}

Not a C program (4, Informative)

erroneus (253617) | more than 4 years ago | (#31504526)

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.

Damn kids (2, Informative)

ucblockhead (63650) | more than 4 years ago | (#31504546)

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.

Load More Comments
Slashdot Login

Need an Account?

Forgot your password?