Circuit Negma

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

Archive for July, 2008

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 »

PCB Layout Notes

Posted by Circuit Negma on July 12, 2008


Created By: Hussein Nosair

Source: Polygons Pours & Copper Regions

* A copper pour on a signal layer is a common part of a PCB design.

* Hatched pour is used for ground plains in an analog design.

* Solid pour is used for carrying heavy currents.

* Solid pour is also used for ground plains meant for EMC shielding.

Posted in Electronics, PCB | Tagged: , , , , | Leave a Comment »

MS OutLook Tweaks :: How to recover deleted items in Outlook ?

Posted by Circuit Negma on July 10, 2008


Created By: Hussein Nosair

One of Microsoft Outlook’s hidden tools is the Recover Deleted Items tool. This tool allows you to recover most if not all of your deleted emails and items, even after you have deleted them from the Deleted Items Folder.

This Tool is not enabled in Outlook by default, and its activation requires a registry tweak using the Registry Editor (regedit).

Remember! Always backup your work before you implement any changes or modification to work under question.

Steps to backup Windows registry file:

  • Click Start
  • Click Run

  • Type in :: regedit and then click OK

  • Click on My Computer.

  • Click on File
  • Click on Export

  • Give this backup a name under “File Name“. use the following template for a filename : reg_mmddyy
  • Click on “All” under Export range

  • Click Save to complete the export registry file.

Steps to Activate the Recover Deleted Items Tools in MS Outlook:

  • IF MS Outlook is running, then CLOSE/EXIT MS Outlook.
  • Click Start
  • Click Run

  • Type in :: regedit and then click OK

  • Expand My Computer by clicking on the (+) on the left of My Computer
  • Expand HKEY_LOCAL_MACHINE
  • Expand Software

  • Expand Microsoft

  • Expand Exchange
  • Expand Client
  • Expand Options

  • Right Click in the big white space to the right, or Click on Edit in the Top menu bar
  • Click New
  • Click DWORD Value

  • Type DumpsterAlwaysOn

  • Double Click on the item “DumpsterAlwaysOn” you just have created
  • Set the DWORD value to 1
  • Click OK

  • Click on File, then Exit to close Regedit. Or click on the [x] mark in the Top right corner of the Regedit window.

Steps to use the Recover Deleted Items Tool:

  • Launch MS Outlook software

Before we launch the tool, I need to mention that this tool work independently on each folder in the Mailbox. For Example, Lets say that you have accidentally deleted some emails from your Inbox Folder. To use this tool you need first to Click on the Inbox Folder, then Follow the following steps:

  • Click on Tools.
  • You will notice that Recover Deleted Items tool is activated.
  • Click on Recover Deleted Items…

Select the emails that you want to recover and then Click on the icon market by the red box in the picture below.

Posted in Uncategorized | Tagged: , , , , , | 5 Comments »