Reputation: 22486
gcc 4.6.2 c89
I am passing a pointer to a function. This pointer will be passed to another function. And depending on the current value, the value will be changed. So in main the value changed will be value changed in the function.
Because I am going through 2 functions. I just wanted to make sure I haven't done anything that would cause undefined behaviour. As this will run on a system with high transcations.
I cannot return the value in the return type, as I need to return TRUE or FALSE so see if the function succeeded or failed.
I have run under valgrind and it reports no errors:
valgrind --leak-check=full --verbose ./ptr
Many thanks for any suggestions,
#include <stdio.h>
#define FALSE 0
#define TRUE (!FALSE)
static int incoming_sdp(int *pcmu_priority);
static int parse_incoming_sdp(int *pcmu_priority);
int main(void)
{
int pcmu_priority = 10;
printf("Start program pcmu_priority [ %d ]\n", pcmu_priority);
if(incoming_sdp(&pcmu_priority) == FALSE) {
/* Something bad happened */
}
printf("Final pcmu priority [ %d ]\n", pcmu_priority);
return 0;
}
/* Removed the processing that will determine of the function is success of failure */
static int incoming_sdp(int *pcmu_priority)
{
/* Pass the value of the pcmu_prority */
if(parse_incoming_sdp(pcmu_priority) == FALSE) {
return FALSE;
}
/* Return true or false if processing was successfull */
return TRUE;
}
/* Removed the processing that will determine of the function is success of failure */
static int parse_incoming_sdp(int *pcmu_priority)
{
/* Now change the value of the pcum_priority */
if(*pcmu_priority == 10) {
*pcmu_priority = 20;
printf("pcmu is 10 changing pcmu_priority to [ %d ]\n", *pcmu_priority);
}
else if(*pcmu_priority == 20) {
*pcmu_priority = 10;
printf("pcmu is 20 changing pcmu_priority to [ %d ]\n", *pcmu_priority);
}
/* Return true or false if processing was successfull */
return TRUE;
}
Upvotes: 0
Views: 189
Reputation: 145829
This program is fine and does not produce an output that depends on undefined behavior.
Upvotes: 1