Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Posts Tagged ‘C++’

Visual C++ 2010 :: Error MSB8009

Posted by Circuit Negma on March 31, 2011


Created By: Hussein Nosair

Date: 3/31/2011

IDE: Visual Studio 2010

Language: Visual C++ 2010

Project Platform: x64

Windows: Windows 7

 

Error:

Error    MSB8009: .NET Framework 2.0/3.0/3.5 target the v90 platform toolset. Please make sure that Visual Studio 2008 is installed on the machine.    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets

Cause:

Platform Toolset is set to v90

Solution:

Set Platform Toolset to v100

1. Select one of your project files. This will make sure that project is selected

2. Click Project > {name.of.your.project} Properties…

3. Expand Configuration Properties

4. Click on General

5. Locate Platform Toolset option on the right hand side

6. Click on the v90

7. Click on the drop down list arrow to your right

8. Select v100

9. Click OK to exit

 

Posted in C++, Visual C++ 2010 | Tagged: , , | 12 Comments »

C Programming :: How to use a variable in multiple/different source files?

Posted by Circuit Negma on July 16, 2008


Created By: Hussein Nosair

What is the best way to declare and define global variables and functions?

Declaration vs. Definition:

1. Declaration is a statement of a programmatic entity (ex. variable, function, union, structure) to be referenced in other parts of a program/code, which has its definition somewhere else.

2. Definition is the actually description, allocated space and initialization of a declared programmatic entity (ex. variable, function, union, structure).

Purpose:

a global variable or function is a variable or function that need to be shared or accessed across several source files, keeping in mind that the definition and declaration is consistent with each other.

Right                                                             Wrong

Definition:

int a;                                                             int a;

Declaration:

int a = 0;                                                       char a = 0;

OR

a global variable or function is a variable or function that need to be shared or accessed within a single source file, keeping in mind that the definition and declaration is consistent with each other.

*** The best way to declare and define a global variable is to place the declaration in a header file (.h) and the definition is a source file (.c).

How-to:

To define a global variable or function; you need to do the following:

1. create a header file with the declaration of variable or function.

Ex:

Common.h

#ifndef _COMMON_H_
#define _COMMON_H_

extern int i;
extern int n;
extern unsigned char Array[];

extern void func1();
extern int func2();

#endif

*** Note: The keyword extern is optional in function declarations

2. create a source file with the definition of variable or function.

Common.c

#include "common.h"

int i;      // Define i and initialize
int n;      // Define n and initialize

unsigned char Array[6] = {1,2,3,4,5,6};   // Define Array and initialize

// Define func1 and initialize
void func1(void)
{
    printf("This is ... function 1 \n");

}

// Define func2 and initialize
int func2(void)
{
    printf("This is ... function 2 \n");

    return 0;
}

*** Note: The declaration source file should include (#include) the definition header file.

3. Main program

#include <stdio.h>              // Include general I/O library
#include "common.h"             // Include defined variables and functions


void func3(void);               // Define Local function
void func4(void);               // Define Local function

int main(void)                  // Main Program
{
    printf("i = %d \n", i);     // Print out initial value of i
    printf("n = %d \n", n);     // Print out initial value of n

    i = 8;                      // Set a new value for i
    printf("i = %d \n", i);     // Print out the new value of i

    n = 4;                      // Set a new value for n
    printf("n = %d \n", n);     // Print out the new value of n

    func1();                    // Call global function = function 1 
    func2();                    // Call global function = function 2

    for(i=0; i<6; i++)          // Print out global Array
        printf("%d", Array[i]);

    // Print out blank lines
    printf("\n");
    printf("\n");

    func3();                   // Call local function = function 3

    // Print out blank lines
    printf("\n");
    printf("\n");

    func4();                   // Call local function = function 4

    return 0;                  // End main program

 }


// Definition of local function 3
void func3(void)
{
     printf("This is ... Function 3 \n");
     printf("Please, Enter a new value for variable i = ");
     scanf("%d", &i);
     printf("The new value for variable i = %d \n", i);

}

// Definition of local function 4
void func4(void)
{
     printf("This is ... Function 4 \n");
     for(i=0; i<6; i++)
     {
          printf("Please, Enter a new value for variable Array[%d] = ", i);
          scanf("%d", &Array[i]);
     }

     for(i=0; i<6; i++)
        printf("a new value for variable Array[%d] = %d \n", i, Array[i]);

}

*** Note: Need to include (#include) the definition header file wherever the global variables and functions  are needed in the program code.

Posted in C Programming | Tagged: , , , | 16 Comments »