C function prototypes syntax

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a general C function prototype syntax question regarding the following scenario:

if I have a project with 3 source files
Main.c // main project source file that calls functions in a2d.c
a2d.h // A/Ddefinitions & function prototypes
a2d.c // A/D Access routines

a2d.c requires #include a2d.h for the definitions
Main.c requires #include a2d.h for the funcion prototypes

should the prototypes for the A/D functions be declared as
1.) char ReadA2D(char);

or do they have to be phrased as:
2.) char ReadA2D(char anyVariableName)

I always thought either was ok but I get an "Illegal symbol" error on the prototype line when I compile if I use option 1. What I find funny is that "anyVariableName" does not have to be the same variable name used in the actual function definition.

Is my understanding, of how to use #defines and prototypes in a .h file in conjunction with separate source files that all require the .h file to be included, wrong? If so what is the proper form/syntax?

Thanks

Erick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Erick,

Which compiler are you using? I use the Imagecraft compiler and it accepts both style prototypes.

Erik

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

here's one technique you might consider using in a header file...
in (exactly) one source code file you define functionproperbody before the inclusion of the header file
i'm going from memory here so bear with me; also, this technique might be compiler-dependent

#ifdef functionproperbody
returnvaluetype function_name( parametertype parametername);
#else
extern returnvaluetype function_name( paramtertype );
#endif

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Both syntax are correct for ANSI C.
// richard

admin's test signature