What does the following means?

This is a discussion on What does the following means? within the C Programming forums, part of the General Programming Boards category; Code: struct StaffRec { char *fname; char *lname; }; typedef struct CDRec *StaffRecPtr; staff createStaff(char *fname, char *lname) { Staff ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    21

    What does the following means?

    Code:
    struct StaffRec
    {
     char *fname;
     char *lname;
    };
    
    typedef struct CDRec *StaffRecPtr;
    
    staff createStaff(char *fname, char *lname)
    {
     Staff newStaff;
    
     newStaff = (StaffRecPtr)malloc(sizeof(struct StaffRec));
     ((StaffRecPtr)newStaff)->fname = fname;
     ((StaffRecPtr)newStaff)->lname = lname;
    
     return newStaff;
    }
    The part on ((StaffRecPtr)newStaff)... Reason of using got to do with void pointer. Can anyone enlighten me? Heap tks....

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    First off, 'Staff' is never defined in your example, so I have no idea what type it is.
    Second, unless 'Staff' is a pointer itself, the typecast and malloc is grossly inaccurate.
    Third, you don't need to cast the return type for malloc. There is never any need to do so in C. If you get a warning about lack of a cast, you're comiling as C++ and not C.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Yes, Quzah is right. This code cannot be compiled with a c compiler but there's hope for it being compiled by a c++ compiler.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does this code means?
    By junkeat90 in forum C++ Programming
    Replies: 6
    Last Post: 01-14-2008, 04:03 AM
  2. Replies: 2
    Last Post: 05-15-2007, 03:30 AM
  3. what does "close wait" and "fin_wait2" means?
    By hanhao in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-18-2005, 05:14 AM
  4. Do you know what this compiler error means?
    By Zalbik in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2003, 03:20 PM
  5. Can someone explain to me what this code means
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2002, 11:36 AM

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