Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bit global_error_flag = 0;
- bit global_data_ready_flag = 0;
- unsigned char A_Function (void) {
- // Do some stuff
- if ( badness ) {
- global_error_flag = 0;
- global_data_ready_flag = 1;
- return 0;
- }
- if ( data_is_ready_use ) {
- global_data_ready_flag = 1;
- }
- return a_value;
- }
- void Other_Function (void) {
- unsigned char c;
- c = A_Function();
- if( global_error_flag) {
- // Do error stuff here.
- }
- else
- if( global_data_ready_flag ) {
- // Do data processing here.
- }
- global_error_flag = 0;
- global_data_ready_flag = 0;
- }
- #define FUNCTION_SETS_FLAGS(code) (code)
- FUNCTION_SETS_FLAGS( c = A_Function() );
- /*************************************************************************
- * FUNCTION : <function_name>
- * DESCRIPTION : <function description>
- * PARAMETERS :
- * Param1 - <Parameter-1 explanation>
- * Param2 - <Parameter-2 explanation>
- * Param3 - <Parameter-3 explanation>
- * RETURN : <Return value and type>
- * GLOBAL VARIABLES USED:
- * Global1 - <Global-1 explanation>
- * Global2 - <Global-2 explanation>
- * Global3 - <Global-3 explanation>
- *************************************************************************/
- unsigned char _a_function(void);
- #define A_Function(ret_val) (*(ret_val) = _a_function(), !global_error_flag)
- ...
- unsigned char var;
- /* call the function */
- if (!A_Function(&var))
- {
- /* error! */
- }
- else
- {
- /* use var */
- var++;
- }
- // Function func
- // Does something
- // Consumes ready_flag and sets error_flag on error.
- int func()
- {
- if (ready_flag)
- {
- //do something then clear the flag
- if (some_error)
- error_flag = x;
- ready_flag = 0;
- }
- //don't mess with the flags outside of their 'scope'
- return 0;
- }
- unsigned char A_Function (bit *p_error_flag, bit *p_data_ready_flag)
- {
- ...
- }
Add Comment
Please, Sign In to add comment