Search code examples
creturn-valuereturn-typefunction-declaration

What return type should I declare a function with if I don't care about the return value?


In my C file, I am calling a function that is defined in a generated file, lex.yy.c:

yy_scan_string(input);

which is declared as following in lex.yy.c:

YY_BUFFER_STATE yy_scan_string(yyconst char *yystr);

And in turn YY_BUFFER_STATE is an typedef:

typedef struct yy_buffer_state *YY_BUFFER_STATE;

None of these are available to include from a header file. While in order to call yy_scan_string I will have to declare it first.

What would be the best way to declare this function in my source file, when I don't care about the return value at all, and it's infeasible to include the type definition of the return type?


Solution

  • The universally accepted procedure is to define the function in a header-file and include that file at the start of the file you call it from.

    If for some reason that header file hasn't be provided you would make it.

    If it's only a handful of functions you could declare them locally in the .c file.

    The function returns a pointer to the structure so you can use the forward declaration:

    typedef struct yy_buffer_state *YY_BUFFER_STATE;
    

    However I can only recommend very strongly you remove those declarations to their own file.