pointer to enum type

This is a discussion on pointer to enum type within the C Programming forums, part of the General Programming Boards category; Can I pass a enumerate type pointer to a function? I have never seen people pass enum type pointer to ...

  1. #1
    C-dummy
    Guest

    Question pointer to enum type

    Can I pass a enumerate type pointer to a function?
    I have never seen people pass enum type pointer to a function?
    why???? is it unsafe data by passing that way???

    enum Color {GREEN, YELLOW, RED};
    void main(void)
    {
    enum Color colorVar = GREEN;

    foo(&colorVar);

    return;
    }
    void foo(enum Color *colorPtr)
    {
    *colorPtr = RED;
    printf(" Traffic light now is RED");
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I have never seen people pass enum type pointer to a function?
    Probably because there was no need for them to do so.

    >is it unsafe data by passing that way???
    Not at all.

    >void main(void)
    This, however, is unsafe. Use int main ( void ) and return 0;.

    >void foo(enum Color *colorPtr)
    Don't forget to declare a prototype or place the function definition before main.

    And remember to include header files for the standard functions you intend to use, but I won't be too pedantic to you this time.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program error
    By cutelucks in forum C Programming
    Replies: 14
    Last Post: 12-21-2007, 10:12 PM
  2. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  3. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 05:17 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21