Development > Coding

Compiling in Visual Studio 2005

<< < (2/4) > >>

Gill_Bates:
Nevermind - I moved the declared variables a bit higher.
I still can't tell if the problem is mine alone, but at least it compiles (with about 150 warnings)

oxyXen:

--- Code: ---void f( void )
{
   foo = [malloc]
   foo = "bar";
}

char *foo;

void g( void )
{
   foo = [malloc]
   foo = "bar"
}
--- End code ---


This is not a problem, but normal behaviour. In this code, when f is used, it doesn't know about foo. g is happy.

ox

Gill_Bates:
Thanks, but I'm not sure we're talking about the same thing-
The thing my compiler complained about was something like:

--- Code: ---
typedef struct something_s
{
   int something;
} something_t;


void someFunction (void)
{
   int a; // this is OK
   if (globalVariable > 0)
      return;
   something_t* t; // This is not OK - must declare below int a
   int b; // this is not OK as well
   ...
}

void OKFunction (void)
{
   int a;
   something_t * t;
   int b;
   if (globalVariable > 0)
      return;
   ...
}
--- End code ---


Furthermore, I suggest putting NULL in any such something_t pointer before it is used.

Mattn:
give my the files and lines and i'll fix this.

but be sure to check out the latest svn

Hoehrer:

--- Quote from: "Gill_Bates" ---The thing my compiler complained about was something like:

--- Code: ---
typedef struct something_s
{
   int something;
} something_t;


void someFunction (void)
{
   int a; // this is OK
   if (globalVariable > 0)
      return;
   something_t* t; // This is not OK - must declare below int a
   int b; // this is not OK as well
   ...
}
--- End code ---

--- End quote ---

Why would this be a problem at all? (mind you i'm not a very good c-programmer as well) if you define variables/structs and do not use/access them before that line there will be no problem in any case. I think your compiler just gives you hints to prevent commons mistakes, but not showing any _real_ errors. ... But that's just a thought.

If this is an error you can't do something like this (this isn't tested though):

--- Code: ---{
int x;
x = SomeFunction();
if ( x ) {
int temp;
temp = x;
// do alot of calculations and displaying temp.
// temp not needed anymore.
}

// At this point if x was 0 temp was never defined at all (no memory reserved)

}
--- End code ---




--- Quote ---Furthermore, I suggest putting NULL in any such something_t pointer before it is used.
--- End quote ---

Good idea. Will see what i can do here in my code as well.


Werner

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version