signigicance of VOID in C language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandhya rani
    New Member
    • May 2007
    • 17

    signigicance of VOID in C language

    1) .What is the Significance of VOID in C language.If possible give me with example.

    2). help me to know about the some of the keywords in C language they r
    AUTO, VOLATILE,EXTERN ,INLINE,NEAR AND FAR.
    pls take out some time and try to give me with examples.
  • nearestniladri2003
    New Member
    • May 2007
    • 11

    #2
    VOID: void (type)-Empty data type

    When used as a function return type, void means that the function does not
    return a value.

    void hello(char *name)
    {
    printf("Hello, %s.",name);
    }

    When found in a function heading, void means the function does not take any
    parameters.

    int init(void)
    {
    return 1;
    }

    Void pointers - Pointers can also be declared as void.

    Void pointers can't be dereferenced without explicit casting. This is
    because the compiler can't determine the size of the object the pointer
    points to.

    Example:
    int x;
    float r;
    void *p = &x; /* p points to x */
    int main (void)
    {
    *(int *) p = 2;
    p = &r; /* p points to r */
    *(float *)p = 1.1;
    }

    Comment

    • nearestniladri2003
      New Member
      • May 2007
      • 11

      #3
      VOLATILE: The reason for having this type qualifier is mainly to do with the problems that are encountered in real-time or embedded systems programming using C. Imagine that you are writing code that controls a hardware device by placing appropriate values in hardware registers at known absolute addresses.
      Let's imagine that the device has two registers, each 16 bits long, at ascending memory addresses; the first one is the control and status register (csr) and the second is a data port. The traditional way of accessing such a device is like this:
      /* Standard C example but without const or volatile */
      /*
      * Declare the device registers
      * Whether to use int or short
      * is implementation dependent
      */

      struct devregs{
      unsigned short csr; /* control & status */
      unsigned short data; /* data port */
      };

      /* bit patterns in the csr */
      #define ERROR 0x1
      #define READY 0x2
      #define RESET 0x4

      /* absolute address of the device */
      #define DEVADDR ((struct devregs *)0xffff0004)

      /* number of such devices in system */
      #define NDEVS 4

      /*
      * Busy-wait function to read a byte from device n.
      * check range of device number.
      * Wait until READY or ERROR
      * if no error, read byte, return it
      * otherwise reset error, return 0xffff
      */
      unsigned int read_dev(unsign ed devno){

      struct devregs *dvp = DEVADDR + devno;

      if(devno >= NDEVS)
      return(0xffff);

      while((dvp->csr & (READY | ERROR)) == 0)
      ; /* NULL - wait till done */

      if(dvp->csr & ERROR){
      dvp->csr = RESET;
      return(0xffff);
      }

      return((dvp->data) & 0xff);
      }

      Comment

      • nearestniladri2003
        New Member
        • May 2007
        • 11

        #4
        EXTERN (keyword): Indicates that the actual storage and initial value of a variable, or body
        of a function, is defined elsewhere, usually in a separate source code
        module.

        Syntax:
        extern <data definition> ;
        extern <function prototype> ;

        The keyword extern is optional for a function prototype.

        Example:
        extern int _fmode;
        extern void Factorial(int n);


        auto (keyword): Defines a local variable as having a local lifetime.

        Syntax: [auto] <data definition> ;

        This is the default for local variables and therefore is rarely used.

        Example:
        int main(int argc, char **argv)
        {
        auto int i;

        i = 5;
        return i;
        }

        Comment

        • nearestniladri2003
          New Member
          • May 2007
          • 11

          #5
          inline (keyword): Declares/defines C++ inline functions

          Syntax:
          <datatype> <function>(<par ameters>) { <statements>; }
          inline <datatype> <class>::<funct ion> (<parameters>) { <statements>; }

          In C++, you can both declare and define a member function within its class.
          Such functions are called inline.

          The first syntax example declares an inline function by default. The syntax
          must occur within a class definition.

          The second syntax example declares an inline function explicitly. Such
          definitions do not have to fall within the class definition.

          Inline functions are best reserved for small, frequently used functions.

          Example:
          /* First example: Implicit inline statement */

          int num; // global num
          class cat {
          public:
          char* func(void) { return num; }
          char* num;
          }


          /* Second example: Explicit inline statement */

          inline char* cat::func(void) { return num; }

          Comment

          • nearestniladri2003
            New Member
            • May 2007
            • 11

            #6
            near (type modifier)

            Forces pointers to be near; generates function code for a near call and a
            near return.

            Syntax:
            <type> near <pointer definition> ;
            <type> near <function definition>

            The first version of near declares a pointer to be one word with a range of
            64K.

            This type modifier is usually used when compiling in the medium, large, or
            huge memory models to force pointers to be near.

            Example:
            char near *s;
            int (near *ip)[10];

            When near is used with a function declaration, Turbo C++ generates function
            code for a near call and a near return.

            Example:
            int near my_func() {}

            far (type modifier)

            Forces pointers to be far, generates function code for a far call and a far
            return.

            Syntax:
            <type> far <pointer definition> ;
            <type> far <function definition>

            The first version of far declares a pointer to be two words with a range of
            1 megabyte. This type modifier is usually used when compiling in the tiny,
            small, or compact models to force pointers to be far.

            Examples:
            char far *s;
            void * far * p;

            When far is used with a function declaration, Turbo C++ generates function
            code for a far call and a far return.

            Example:
            int far my_func() {}

            Comment

            • sandhya rani
              New Member
              • May 2007
              • 17

              #7
              Thanks Dear friend n group members for u r most valuable reply.I want some more keywords in C language they r
              REGISTER,STATIC ,UNION,SIGN AND UNSIGN
              pls take out some time and try to give me with examples.

              Comment

              Working...