1

Newbie question.

I am trying to get libcork to compile with VS2010.

In C I guess you typically have to declare variables at the beginning of the function like this:

void
cork_hash_table_clear(struct cork_hash_table *table)
{

    DEBUG("(clear) Removing all entries");

    size_t  i;  // <--- fails to compile unless moved before DEBUG.
    ...

But libcork is rife with definitions/declarations as they are used in code. I wonder if there is a VS compiler option that allows this? I'm sorry if this question is not new, but all I get is a syntax error and I don't have any helpful terms to use to search the VS docs.

Paul
  • 2,973
  • 6
  • 31
  • 40
  • you can compile this as C++ though – perreal Aug 13 '12 at 18:32
  • No, it's a [well-known grievance](http://stackoverflow.com/questions/146381/visual-studio-support-for-new-c-c-standards) that visual studio supports only a severely limited number of C99 features. – cnicutar Aug 13 '12 at 18:33

1 Answers1

2

Intermixed declarations and statements within a function were introduced into C in the 1999 version of the standard (C99); unfortunately VS decided not to follow the standard past the 1990 version.

You may be able to compile the code as C++, although this could well break in interesting ways as C is not a strict subset of C++. Herb Sutter recommends using Intel CC or gcc if the code is not compatible with C++.

The question Visual Studio support for new C / C++ standards? has some interesting content, although it covers C++ as well (where VS is far better at keeping pace).

Community
  • 1
  • 1
ecatmur
  • 152,476
  • 27
  • 293
  • 366