Tomer Gabel's annoying spot on the 'net RSS 2.0
# Tuesday, 26 September 2006

This wasn't an easy riddle by any means. One has to either have a lot of experience developing both C and C++, or take a very hard look at the standards to spot the differences. Bottom line? I couldn't find a solution. Fortunately a brother and a colleague both came through:

Solution 1: Ugly Hack

Tal (one of my colleagues at Monfort) came up with the following concept:

#include <stdio.h>

int main()
{
	int a = 1//**/10
	;
	printf( "%d\n", a );
	return 0;
}

This deserves some explanation: originally C did not support single-line comments (//); these were added to a later version of the standard called C99. So what happens is, if you compile this code with an old C compiler the "//**/" string is parsed as a division operator and an empty comment, resulting in 1/10=0. A modern C compiler (or any C++ compiler) will treat the entire line as a comment and the result is 1.  One way to easily test this is to compile with gcc -std=c89 file.c.

Solution 2: Elegant Hack

I didn't have the time to properly look for a detailed comparison of C and C++ standards (I'll save you the time: this looks to be a good source). There are probably quite a few ways to achieve the goal, however my brother Mickey suggested one I find quite elegant:

#include <stdio.h>

int main()
{
	printf( "%d\n", sizeof( 'c' ) == sizeof( char ) );
	return 0;
}

Seems odd? Apparently one of the (relatively small) breaking changes between C and C++ is how character literals are handled. In C a character literal takes the type int, whereas in C++ a character literal has the expected size (source).

Tuesday, 26 September 2006 10:43:14 (Jerusalem Standard Time, UTC+02:00)  #    -
Development

Just when I was about to resume posting with full speed, my laptop breaks down. Another day, another dead hard drive. Hope to have it all sorted out in a few days.

As an aside, I updated to dasBlog 1.9. The upgrade was smooth (couple merged files and a lot of binary uploads) and everything seems to work - please let me know if something's wrong.

Tuesday, 26 September 2006 10:10:14 (Jerusalem Standard Time, UTC+02:00)  #    -
Personal
# Tuesday, 12 September 2006

Write a program that compiles under both C and C++ compilers, and outputs "0" for C and "1" for C++ (or whatever, the actual numbers are not the point). You obviously may not use compiler-dependant macros, __CPLUSPLUS__-type macros or anything of the sort.

Once again, I'll post the solution in a couple of days.

Tuesday, 12 September 2006 15:40:55 (Jerusalem Standard Time, UTC+02:00)  #    -
Development

Here's one possible solution for the riddle I posted a few days ago:

  1. Replace i < N with -i < N
  2. Replace i-- with N--
  3. Replace i < N with i + N

This isn't a particularly hard riddle - it took me about 10 minutes to come up with the solution, although I imagine a developer with more recent C experience will be much quicker. Regardless it's a pretty good way to tone those C muscles.

Tuesday, 12 September 2006 15:23:00 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
# Monday, 11 September 2006

These last few months have been some of the busiest of my life. Back in May I decided to postpone my studies in the Technion to resume working for Monfort full-time, and in the interim managed to complete several projects, visit several countries (besides China, which I already wrote about, I visited Japan, Hong Kong and Korea).

The net result was very little free time, which reflects in the post count:


(if you can't see this, you need glasses)

I want to get back on the horse, as it were, but I would also like to avoid ridiculous pledges that I have no idea whether or not I'll be able to hold up ("I pledge to write at least two major posts a week! No no, lets aim for something more feasible. I pledge to establish contact with an alien civilization by the end of the year!"), I'll make whomever is reading this a trade: I'll do my best to write more and more content, and you'll do your best to let me know what interests you.

Just to get the taste buds going, here are the current posts in the pipeline (i.e. open draft in Live Writer I'm trying to consistently work on):

  • Some free power tools (gnuplot, SVG, other GNU tools)
  • A comprehensive post about wikis, specifically MediaWiki and how our organization uses it to our advantage
  • A post about my two trips to Tokyo
  • Thorough review of the new audio equipment I've been buying lately
  • Occasional music/movie recommendation

If there are any specific points of interest, give me a holler...

Monday, 11 September 2006 16:32:01 (Jerusalem Standard Time, UTC+02:00)  #    -
Personal
# Sunday, 10 September 2006

Virtual PC is free, which is good. It is reasonably fast and functional, which is also good.

It has some bugs, which - surprisingly - isn't good. One of those is an apparently ubiquitous "Network adapter... failed to initialize because the address is a null address." A solution can be found via this blogpost. Weird, but works:

  1. Examine the key value at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\<nnnn>\DriverDesc to locate the desired host adapter where <nnnn> is a four digit number.
  2. Look at the GUID value for the NetCfgInstanceId key value.
  3. Add the DWORD key at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VPCNetS2\Parameters\Adapters\<guid>\Flags and set the value to 0 where <guid> is the GUID found in step 2.
  4. Restart the computer.
Sunday, 10 September 2006 17:38:59 (Jerusalem Standard Time, UTC+02:00)  #    -
Software
# Friday, 08 September 2006

A friend sent me this riddle (which I imagine isn't his, but nevermind) via mail, and I thought it cute enough to share:

Find three ways to change/insert/delete a single character in the following code, so that the resulting code will print 20 star characters (*). Remember, for each solution you can only change one character, and there are at least three different solutions.

#include <stdio.h>

int main()
{
    int i, N = 20;
    for ( i = 0 ; i < N ; i-- )
        printf( "*" );
    return 0;
}

I'll post the solution in a few days, feel free to yell "eureka" in the comment section or whatever.

Friday, 08 September 2006 18:26:24 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
# Tuesday, 22 August 2006

Microsoft has done a stellar job on Windows Live Writer. Even at beta it already supports (out of the box, no less!) a vast number of blogging engines, including dasBlog. It also supports a blog autodiscovery feature called RSD, which according to Omar will be featured in the upcoming dasBlog 1.9.

The draft feature is simply awesome: open up Writer, start typing and you never have to worry about your text going to hell (there is also an autosave feature). The WYSIWYG editor is extremely robust, lets you edit your posts using your own blog's stylesheet and has excellent picture embedding features. Although I could easily go into HTML editing mode and edit the HTML directly, I no longer see any point doing it, which saves a hell of a lot of hassle and time!

Never a sucker for web applications (AJAX or otherwise), this is a positive boon for me. Good job, Microsofties!

Tuesday, 22 August 2006 13:49:20 (Jerusalem Standard Time, UTC+02:00)  #    -
Personal | Software
# Sunday, 20 August 2006

After my foray into the world of IBM Model M keyboards, followed by a few months using the impressive Microsoft Natural Ergo 4000 I eventually came to the conclusion that the Model M was the better keyboard of the two. The tactile response of the Model M is unmatched on any keyboard I've ever used, however the lack of Windows keys (and misbehaving Shift key - that was one old keyboard!) was a real pain in the ass.

I was anxious to try out two keyboards: the elitist Das Keyboard (the original version - there was no Das Keyboard II at the time) and the Unicomp Customizer, which is based on the original Model M technology. The possibility of a brand new Model M with Windows keys was simply too difficult to pass up and I opted for a black, 104-key USB Customizer (which looks wicked cool, check out the image on the right!)

Although I've only been using this keyboard for a few hours I can safely say that it's the best keyboard I've ever used. The tactile response is simply astounding -- basically everything I've said before about the Model M is equally true for this keyboard. Unfortunately this also includes the fact that it's a very large keyboard, which can sometimes mean too large; the finger travel for some of the keystrokes is a little much for my really small fingers (particularly when I have to right-shift or use one of the function keys). I guess the best thing ever would be a Microsoft Natural-style ergonomic keyboard with buckling spring keys (a la Model M). Maybe even one with blank caps... one can only hope :-)

As an aside, the Israeli tax is murder. Aside from exorbitant shipping price (not PCKeyboard's fault, it's just the way things are...), the Israeli customs laws dicatate a 15.5% VAT on every package whose value is higher than $50 (the tax can be higher, depending on the content), but they include shipping in the tax calculation!

Sunday, 20 August 2006 18:53:53 (Jerusalem Standard Time, UTC+02:00)  #    -
Development | Personal
# Monday, 31 July 2006
From a newsgroup post, I particularly liked this reply by Hans-Bernhard Broeker:
> Luckily, it was the only bug introduced this way.

... the only one you've *found* so far.  Absence of evidence is not evidence of absence.

Monday, 31 July 2006 18:30:39 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
Me!
Send mail to the author(s) Be afraid.
Archive
<2006 September>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
All Content © 2024, Tomer Gabel
Based on the Business theme for dasBlog created by Christoph De Baene (delarou)