Sunday, February 14, 2010

Errors and Fixes for Programming in MS Visual Studio 2008

It is the first time I am programming in C using Microsoft Visual Studio 2008.
Here are some of the silly mistakes I made and figured out the solutions for the errors.

Error 1: bError 1 error LNK2005: _main already defined in

Fix: check if you have two main functions anywhere in the project. It could be two files with main functions.

Error 2: error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0

Fix: int my2dArray[num][num]; /* WRONG! can't allocate using non-const variable */

so initialize array this way:
int **my2dArray = (int**) malloc(num * sizeof(int*));

Reference :

No comments:

Post a Comment