Creating entities for lists

To create entities with which you can populate lists, you can use the function csnew or the CSNEW macro. The function csnew takes the size of an entity as an argument and returns a pointer to a newly created entity which is going to be placed in a list. The size argument is normally expressed as a “sizeof” construct involving the “typedef” for the entity. For example, a code fragment to create a request entity would be:


RREQ *rqp;

rqp = (RREQ *)csnew(sizeof(RREQ));

This type of statement was used so often that the CSNEW macro was created. Using this macro, the above fragment becomes:


RREQ *rqp;

rqp = CSNEW(RREQ);

While this macro takes care of the multiple references to the type name in this case, casting is still a way of life when dealing with entity pointers.

You must create all entities for use with list or event functions using CSNEW or csnew. You should note that while the standard C runtime library also uses character pointers to return an allocated block of memory, such a block of memory cannot be used with the list functions. Furthermore, the address of a static or automatic variable cannot be used with these functions either.