Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing enumerations by reference...garbage value returned to main
    primarykey
    data
    text
    <p>I'm building a validation function for a particular enumeration data type. The validation function returns 0 (false) or 1 (true) if string passed is valid. At the same time, if the string is valid, then the enumeration subType is then populated with the correct entry. </p> <p>As the code is, it correctly populates subType in the function. I print the entry to the screen to check. But when I return to the main (see below), I get a garbage value (sometimes '11871397') when I print the string. </p> <p>I've even tried this with or without declaring subType as const. I have a number of other validation functions written like this and they all handle the reference type correctly, which has led me to believe that it is an issue with the enumeration.</p> <pre><code>int val_subscriberType (char str[], const enum ns1__subscriberType *subType ) { if (strcmp(upStr, "PREPAID") == 0) { enum ns1__subscriberType subType = ns1__subscriberType__prepaid; printf("SubscriberFunction: %d \n", subType); return 1; } else if (strcmp(upStr, "POSTPAID") == 0) { enum ns1__subscriberType subType = ns1__subscriberType__postpaid; printf("SubscriberFunction: %d \n", subType); return 1; } return 0; } </code></pre> <p>Main</p> <pre><code>char *recRetTest = "aggressive"; enum ns1__recurrentRetrySchemaType recRet; if ( val_recurrentRetrySchemaType (recRetTest, &amp;recRet)) { printf ("\nRecurrent Retry Schema main: %d \n", recRet); } </code></pre> <p>P.S I've taken out the extra code where I convert the string to upper case etc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload