- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Before Windows 3.0 adding resources to an executable was a majestic PITA, so this was a common trick. Same for MZ and NE executables. It's not that the code is wrong. It's that the OP hasn't been in the business long enough to remember resourceless executable formats (the alternative solution was to make your own exe file "suffix" and tagging your resources there one after the other, but you were doing so as a custom solution without benefit of any kind of specific OS support).
Admin
Whoosh!
Admin
I'm certain this has been pointed out but jeeezuz that's perfectly normal when dealing with it or atmel shit and gimp actually will export an image as c code.
wtf what a waste of a good wtf.
Admin
It's common to embed resources in the source code in embedded projects, especially if the OS has no resource system. Sometimes there is no OS nor any filesystem, and it's the only way to do things.
The programmer that set that up at least defined the bitmap in a standard format so people coming along later could open it in paint and edit it even if the original source file got lost, that's pretty damn decent. I would have expected a device-specific format with no header.
Admin
Spectrum, those were the days! I remember drawing my 8X8 boxes on a piece of paper to calculate the boolean number corresponding to each line of the image... lol
Admin
That code seems to come from an file used for an 8051 uC which was compiled by KEIL C51 Compiler. This is why he couldn't find any makefile. And if I'm right and the code was for an 8051, storing bitmaps as const c-arrays was the only way to handle bitmap data as nobody wanted to implement a filesystem to handle those bitmaps....
So I personaly can't find the WTF... except that the author wasn't able to find out which compiler was used...
Admin
Well, just do a
strings
which xboard.real
It's a better solution than depending on 9000 image files which are conveniently located in /usr/share/beatmewithaclub .. no wait, in /usr/local/fsckmeharder.. no wait.. ARGHHH..! And on a freaking image library and on correctly handling all these stupid error conditions.
"Opening Files" must die.
Admin
"Telepathic gecko this way"?
CAPTCHA: amet, as in "amet Bill Gates and he told me to go away"
Admin
Is this bad? I do it all the time...
Admin
As some already said, this might look like a WTF to the IT guys on here, but for small embedded devices without an OS or filesystem it's actually the standard way to do it. And there's a whole lot of those out there.
Admin
Imagine if the original developer had used some linker/loader functions to do this...
After the code had been "passed around" a bit he'd be totally up a certain creek without a rowing implement.
This is the easiest, most reliable, compiler-independent way to do it.
The WTF is when you don't do this and instead write a program with 22000 files to be loaded at runtime (eg. Photoshop). How do you test that build to make sure there's none missing?
With the c-bitmap you know there's a missing file because the compiler will tell you all about it (usually in upper case letters).
Admin
I think c-bitmaps make sense even in the world of quad-core multi-gigabyte Windows coding..
Admin
Nice. This reminds me of embedded C projects. There was literally no file system in this board we were working on, so we basically had to have the files, indeed, as c-bitmaps.
Ahh, the good ole days.
Admin
Yes, plus I(!) know how those files have been created by whom and what they're fore. Those files are autogenerated by a tool. Plus the guy handing this in is pretty clueless about his work.
And a sidenote: the name he had chosen to submit this under is pretty obvious what clients code he had posted (so if wanted it could be tracked back to the supplier unable to proper handle code and knowledge about compiling it). A real smartass...
Admin
I'm pretty sure I've seen this somwhere before, no idea where, tho.
It looks to me like wanting to add bitmap resources to the executable when no other way of doing this is available.
Admin
C bitmaps have been around for ages. Typically they have the extension xcf. They are a (bit old-fashioned) way to include bitmap resources in compiled C. Moreover, unlike other ways to include resources, they will work in a cross-platform context. There are graphics editors that will convert a bitmap to C and vice versa, so nothing WTF about that either.
The only possible WTF is if this guy hand-coded his bitmaps and/or uses a non-xcf format.
Admin
Would you care to point us at the documentation for that feature? For a while I embedded data with (IIRC) objcopy and linked the resulting .o files into my executable, but that would not guarantee the correct alignment, so sometimes the string would appear as garbage when accessed. In the end I used a script 'bin2s' that converted a binary file into assembly statements for the alignment and data; but if GCC now has a way to do that directly I'd like to know how it's done.
Admin
This is not really a WTF. The developer is probably working on an embedded system, perhaps one that does not even have a file system. On such a system, this is a sensible, safe and portable way of putting resources in to your code.
Admin
The real WTF is having four pages of comments all saying that it's not a WTF because of embeded blah while most humans would understand the point after 1-2 comments.
Admin
Hmm, some time ago XBM and XPM files made perfect sense ... packaging bitmap data in source code form therefore does not scream out at me as being totally weird. Oh well, maybe I'm just too old for this shit ...
Admin
Maybe this was an embedded system, with no operating system and hence no file system.
The question would then be how this method is worse than some other methods the original developer could have used to include the bitmaps in the executable? And how is the used method any worse?
After all the files only need to be re-compiled when the bitmap is updated.
Admin
The original file should exist in source control. As part of the build process those C files are generated automatically from the original bitmap files, and the code is then compiled. No one with a shred of common sense would think of editing those files manually. The only WTF here is that either:
a) They don't use source control since they appear to have 'lost' the original makefiles. b) The person submitting this was a moron.
Oh, and for the record, it's not a windows trick. Windows has resource dll's for that purpose. The code is most likely to have come from linux or an embedded environment.
Admin
I don't understand - someone posted a WTF, but it turns out that the WTF is, on closer inspection, not in fact a WTF? In effect, what we're saying here is that the original poster didn't understand the code? That he is mocking someone for being stupid, but has actually demonstrated that it is he who is the incompetent fuckwit?
Why, that NEVER happens on The Daily WTF! Maybe only 95% of WTFs posted here follow that pattern!
Maybe this site's name should be changed to Daily Passive-Aggressive Geek With an Inferiority Complex and a Massive Chip on His Shoulder? DailyPAGWaICaMCoHS for short.
Admin
perhaps he was developing for an embedded system where it maybe didn't have a filesystem. not a wtf.
Admin
Thank God you got through!
Admin
You're all so busy complaining that you're missing a great meta-WTF here.
Admin
No wtfs here. This is development on an embedded platform where there might not be (probably isn't) a file system to allow the program to load up graphics. So this is a standard way to put the graphics in to the executable.
Admin
Well i did have to hand copy it and type it in manual from a hex editor
Admin
it's called an embedded resource you hapless programming newbie
what the hell do you think a .xpm is?
Admin
This is actually quite useful if you don't have a file system. A controller being a rather embedded thing, probably does not have a file system. Also, if you embed the bitmap in the binary in this way, you don't need to fopen() and load the bitmap, you can just pass a pointer to the correct region in memory.
Of course you want to autogenerate that code then, rather than manually write this file (as seems to have been done here, cfr the comments), but that's a different matter entirely.
Admin
When I worked for the U.S. Air Force Reserve, there was a COTS product formerly called DEPCON (I have no idea what it's called now) that was essentially a document distribution clearinghouse. At any rate, it handled bitmaps the same way. The files had a .bmp extension but inside, they were C header files. Many of them had interesting variable names like const int FNORD[] = { }; and const int PINKY[] = { }; and so forth. I found it quite amusing.
Admin
This seems like the naive way to get bitmaps loaded onto a device without a proper filesystem. Is there a better way to do this?
Admin
All the people who made fun of this ("the goggles!") have just betrayed themselves as fakers who know nothing about programming but just repeat the same stuff every fucking time. Thanks in advance for chastising them.
Admin
Maybe someone programmed some kind of embedded system to post comments talking about how normal it is to embed images in source.
Admin
Nah. It's latin. Kinda like frist -- only a bit late...
Admin
Why is storing bitmaps as C-files in an embedded project a WTF? I'll give you a reason why it's not: C is roughly standardized, the file systems and resource managers one would use are usually not.
Admin
About the image : people controlled by brain-washing Mickey helmets should go to the left.
Admin
No it is not a WTF to embed binary resources in your program executable.
But using a translator to generate C-Code from the binary data only to let the compiler write the original data in the object file certainly is.
If your tools do not allow you to reliably embed binary resources in your executables and you need to use such carco-cult-techniques then your tools are broken and the real WTF is not to replace them with tools that support that directly; especially if your target environment requires to do this often.
(Chances are high that this is not the case and you do this only because you do not know your tools; you know only the C-Compiler and use it as a hammer to pound in screws - learn what the screwdriver is for).
From the description of GNU objcopy:
And about the complaint it turned out misaligned sometimes:
This is a classic WTF, almost as big as a WTF can get. Which turns out to be using XML. For anything (than text markup).
CAPTCHA: consequat Why not consequently run a spell-checker on the CAPTCHAs?
Admin
Not sure why you'd see this as a WTF. You need to store the bmp somewhere. In a modern world it might be a resource or external file, but if space is limited, the obvious place to store it is within the executable. So writing a utility to convert small bitmaps to C source code could be reasonable.
Admin
Admin
"The programmer that set that up at least defined the bitmap in a standard format so people coming along later could open it in paint and edit it even if the original source file got lost, that's pretty damn decent. I would have expected a device-specific format with no header."
You're right, this is almost an ANTI-WTF. A bitmap header with useful things like dimensions. It could have just been presented as a giant bitfield with no comments.
Admin
Chances are high that you have very limited real world experience with embedded programming, where replacing your tools isn't trivial. Maybe there is another tool that supports this; it might cost too much, and it might be worse in other ways.
Coding a simple binary-to-C encoder is a trade-off that the original coders might have decided was worthwhile. You have no idea what their constraints were, and calling them on their knowledge of the compiler and their tools betrays your own inexperience.
Besides, it's a pretty simple and straightforward task, and writing a well tested tool to do this would take most programmers about half the time it would take them to read all these comments.
How unprofessional it would be to shell out for a new tool, or building binutils or similar for the platform (and incurring the testing burden that entails.)
Admin
You don't have to read from disk and you don't have to distribute all kinds of bitmap files, just one executable. It's not that uncommon to do this.
Admin
See
http://en.wikipedia.org/wiki/X_BitMap
Admin
(Irony: I hit submit to post this and guess what happens? 2nd try... 3rd...)
Admin
you can pass the binary file directly to 'ld' by prefixing it on the command line with "-b binary".
you can include it directly into an assembly file using the ".incbin" directive.
Admin
It's not the worst idea ever in concept. It's a portable way to include image data into a binary, which is useful in embedded environment where you might not have a separate filesystem to hold these things.
TRWTF is that he rolled his own. XPM is a standard file format supported by a number of image editing and conversion tools that is valid C code and can be just #included into a project. Although I think that XPM is a pretty limited format and might not support all the features that .BMP does (e.g. 24-bit color).
Admin
Actually this is not necessarily a WTF...
Converting BMP files into C files could be useful if you're required to bake the BMPs into your executable image while perhaps supporting multiple endianesses, processor architectures, executable formats, compilers and linkers -- i.e. you can't use some single well defined method of resource packaging.
Of course it's better to create these C files as part of the build process and not keep them in a VCS.
Admin
Alex, you are the weakest link.
Admin
Why does the original article put "bitmap" in quotes?
Ask your dad what a bitmap is.