RSSAmplifier

Blog

Hard to C

Look and you will C -- Learn and you will C++

hardtoc.comRSS feed ↗10 posts

Latest posts

Reordering Arguments

When a C program runs, it usually receives any command-line arguments through the parameters argc (argument count) and argv (argument vector). It is up to the program to interpret the contents of this array of strings. There are many ways to do this, one of the simpler solutions is the getopt function (in the following, getopt will refer to both getopt and getopt_long). One extension some getopt…

Moving to Jekyll

I am moving this blog to Jekyll . While WordPress has worked quite well for the past seven years, I feel it is too much effort for a site that might as well be static. This is pretty much the stock Jekyll generated site using the Solarized light color theme, Source fonts, and a few icons from Font Awesome . Source is here . One sad thing is that support for comments is gone. I could add something…

Not Quite Monokai

TextMate is a popular text editor for OS X. Since the first release 10 years ago, a lot of people have contributed color themes, many of which have been ported to other editors. If you are using a Windows or Linux text editor with such a conversion, you might be looking at something slightly different than what the designer intended. This quote from the Wikipedia article on RGB sums up the…

Time Difference

This post is based on a discussion about Progress Bars of Life , where I was foolish enough to claim that printing a text string representing the difference between two times could not be that hard in C. It is not hard, but turned out not to be entirely trivial either. The problem we will consider is; given two tm structs , compute the difference in time between them, in such a way that we can…

Move Semantics Podcast

The Visual C++ Weekly had a link to a podcast with Scott Meyers from ACCU 2011 which I thought was great: link .

Long Division, Part 3

I ended part two of this series with an open question: And of course I can’t help but wonder if the CLR is compiled with Visual C++, so doing arithmetic on 64-bit numbers in C# and other .NET languages ends up at the same runtime functions? I don’t have a lot of experience in debugging the CLR myself, so I asked Brian Rasmussen if he might be interested in taking a look at it. He was kind enough…

Move to Parent

This post is inspired by a discussion regarding a coding snack done by lanux128 on DonationCoder . A user requested a tool to add a context menu entry that would copy selected files and folders to the parent folder. Moving folders is one of those tasks that appear trivial. But as always, the devil is in the details. To keep it simple , we will assume regular files and folders in a filesystem where…

Quoting Command-line Arguments

Raymond Chen recently blogged about the way CommandLineToArgvW treats quotes and backslashes. Parsing the command-line into argv[] is something I have had to fight with as well, so besides pointing to Raymond’s excellent post, I wanted to add a few comments of my own here. We are examining how command-line arguments with spaces and quotes are handled. Part of the problem comes from the fact that…

Long Division, Part 2

In part one I talked about the support functions in the C standard libraries of various x86 32-bit compilers that perform arithmetic operations when you use 64-bit integers in your code. While updating WCRT to work with the latest Visual C++ compilers, I was writing my own implementations of these functions, and naturally I tested them against the versions supplied in the VC CRT to verify they…

Long Division

Integer types with at least 64 bits have been a part of the C standard for a while now (they were added in C99, and were a standard extension in many 32-bit compilers before that). But have you ever wondered what exactly happens when you use them? Consider the following function (substitute long long with __int64 if you are using an older version of Visual C++): long long div64 ( long long x ,…