Month: August 2017

A new “Hello, World!” for C

August 27, 2017 Code No comments

Most of us have a good idea how to write a simple “Hello, World!” program in C, but sometimes it feels a little too easy. Luckily, we can always make it more of a challenge!

Consider a hypothetical situation where many symbols are banned, such as ", ', \, #, {, and }, and we aren’t allowed the string Hello, World! as a subsequence in the code. How would we write a “Hello, World!” program then?

Is it impossible, because we can no longer use {} to write a block of code for a function? Is it impossible, because we can’t actually embed the string?


Using the Visual C++ compiler on Linux

August 11, 2017 Code No comments

It is a fairly common practice to compile Windows application on Linux build servers. However, this is usually done through an approach called cross-compiling. The essence of this approach is using a compiler for Windows applications, but the compiler itself is a Linux application. Usually, the compiler used for this is MinGW (or MinGW-w64 these days), a GCC implementation for Windows.

This works great when porting traditional Unix applications to Windows, since it meshes nicely with the traditional build system on Unix-like systems. But it is rather poor for standalone single .exe applications, which are more common in the Windows world. MinGW has a few DLLs that are needed to run the applications it compiles, and that ruins the single executable experience.

The traditional way to build these simple applications in the Windows world is with the Microsoft compilers, usually in the form of Visual C++. These compilers are fairly nice, but they have one problem: they do not exist as cross compilers. (Well, they can cross compile between different processors, but the compilers themselves will only run on Windows.) What do we do then? Do we resign ourselves into not having single executable applications, or do give up and buy a Windows build machine?


A polyglot header for Python and cmd.exe

August 4, 2017 Code No comments

After seeing Raymond’s post on polyglot launchers for Perl and JScript with batch files, I decided to present one for Python:

@python -x "%~f0" %* & goto :eof
# Your Python code here.

This one simply use the special python flag -x to ignore the first line, which is somewhat analogous to the -x Perl flag, but much simpler.

I also have an alternative Perl polyglot header that does not require the special flag -x.

@rem = '--*-Perl-*--
@perl "%~f0" %*
@goto :eof
undef @rem;
# Your Perl code here.