Archive for October, 2008

Visual Studio 2010 CTP Released

Uncategorized No Comments »

Maybe this news is a bit old but Visual Studio 2010 CTP was released, you can get it at the following location:

Visual Studio 2010 CTP Site

For you who don’t know, CTP means Community Technology Preview and can almost be regarded as a public beta version.

For C/C++ developers, you can find more info on the next version of Visual C++ 2010 on the Visual C++ Team Blog. I’m glad to see that IntelliSense for VC++ is being improved since in 2008/2005 it’s a quite horrible technology. This version also has support for some C++0x functionality.

ASP.NET – Name Ambiguous by Nature?

Uncategorized 1 Comment »

The ASP.NET logoFirst of all, I have to mention that this colleague has been a C and ASM programmer for most of his lengthy professional career, I won’t mention his name here but let’s just call him “Joe the Programmer” in light of current braindead naming schemes.

Joe the Programmer recently started programming with the .NET framework but yesterday came to a stop. When he was asked to help out with .NET development using ASP.NET, he took some time and to his amazement couldn’t find the ASP.NET programming language in the Visual Studio “new project” dialog.

At first this made me chuckle and I brushed it off, but then I realized he was correct to assume that there should be an ASP.NET programming language. After all, there used to be an ASP programming language although it looked suspiciously much like BASIC.

After explaining that ASP.NET is not as much a language but a technology, he went on his way and continued programming.

This all made me think that maybe the name, ASP.NET, is ambiguous, vague and might be a concept difficult to grasp for guys like Joe the Programmer. I just hope that he has a concept of OOP to go along with his newly found knowledge of ASP.NET.

Amount of Digits in an Integer

Uncategorized No Comments »

Here’s another little snippet that might come in handy in your programmatic travels. I’ll show you an example of usage below, which might also be of interest to you. The code presented is in C, not C++. First, the code to count the amount of digits in an integer:

const size_t intlen(long long int Num)
{
	size_t out = 1;
	while (Num /= 10) ++out;
	return out;
}; // numlen

Looks simple enough; simply count the amount of times we can divide the number by 10 without the result being zero. This function takes a copy of an int (or long long) so that we don’t have to copy the number inside the body of the function and returns a size_t (unsigned int).

As for the usage example, it’s a bit more complex and might seem a bit “obfuscated” at first, but fear not, I will explain below.

void inttoa(long long int Num, char** RetVal)
{
	size_t neg = (Num < 0);
	size_t len = intlen(Num) + (neg ? 1 : 0); // add one for the "-" character
	size_t i;

	*RetVal = (char *) malloc(sizeof(char) * (len + 1));

	if (NULL == (*RetVal))
		return; // bad malloc

	if (neg)
		Num = -Num; // make pos if neg

	for (i = len; i; (Num /= 10), --i) // loop backwards
		(*RetVal)[i-1] = (char)((Num % 10) + '0'); // add modulo to char zero

	if (neg)
		(*RetVal)[0] = '-'; // first char

	(*RetVal)[len] = 0; // last char, null terminator
}; // intttoa

As you might have suspected, this function converts an integer to character string. First, we determine if the number is negative and retrieve its length with the help of the previous function. We allocate a character string with the length determined and start appending a character to the string.

You can use it like so:

char* mystring; // don't allocate, don't do anything
inttoa(42, &mystring); // simply pass it to the function

// do things with the string

free(mystring); // you *do* have to free() the string though

Flattening Multidimensional Arrays

Uncategorized 1 Comment »
Edit: Thank you, fixitman for the insightful comment; the code has been fixed to work with non-square arrays as well.

In an effort to produce a better performing multidimensional array, I would like to share the following with you. Say we have a Matrix (or multidimensional array) of 5 x 5 integer elements, M. In order to allocate such an array in C++, we use the following code:
Read the rest of this entry »