Difference between pages "r6:Function:stack new" and "r6:Function:stack pop"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
==Source Files==
==Source Files==
  /src/stack/stack_new.c
  /src/stack/stack_push_pop.c
  /inc/liblfds.h
  /inc/liblfds.h


==Prototype==
==Prototype==
  int stack_new( struct stack_state **ss, atom_t number_elements );
  int stack_pop( struct stack_state *ss, void **user_data );


==Parameters==
==Parameters==
''struct stack_state **ss''
''struct stack_state *ss''
: A pointer to a pointer onto which is allocated the state which represents this stack.  Set to NULL if stack creation fails.
: A stack state as allocated by ''[[r6:Function:stack_new|stack_new]]''.


''atom_t number_elements''
''void **user_data''
: The maximum number of elements which can be present in the stackThese elements will be allocated when the stack is created.  If not all elements could be allocated (malloc() fails), stack creation fails.
: The address of a pointer into which the user data will be placedIf the stack is empty, ''*user_data'' is not modified, as NULL is a valid user data value.


==Return Value==
==Return Value==
Returns 1 on success and 0 on failure, with ''*ss'' being set to NULL on failure.
The return value is 1 upon successful pop, 0 upon unsuccessful pop.  Popping fails only if the stack is empty.  Note that on an unsuccessful pop, ''*user_data'' is untouched; it is not set to NULL, since NULL is a valid user data value.  Only the return value indicates whether or not the pop was successful.


==Notes==
==Notes==
This function instantiates a stack.
No notes.


==See Also==
==See Also==
* [[r6:API:Stack|Stack]]
* [[r6:API:Stack|Stack]]
* [[r6:Function:stack_delete|stack_delete]]
* [[r6:Function:stack_push|stack_push]]
* [[r6:Function:stack_guaranteed_push|stack_guaranteed_push]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/stack/stack_push_pop.c
/inc/liblfds.h

Prototype

int stack_pop( struct stack_state *ss, void **user_data );

Parameters

struct stack_state *ss

A stack state as allocated by stack_new.

void **user_data

The address of a pointer into which the user data will be placed. If the stack is empty, *user_data is not modified, as NULL is a valid user data value.

Return Value

The return value is 1 upon successful pop, 0 upon unsuccessful pop. Popping fails only if the stack is empty. Note that on an unsuccessful pop, *user_data is untouched; it is not set to NULL, since NULL is a valid user data value. Only the return value indicates whether or not the pop was successful.

Notes

No notes.

See Also