Is ANSI_DECLARATORS something related to C ?

V

velvetyuan

I'm not sure whether it is proper to post it here, but I regard it at
least has something to do with C++.
Let me try to clarify my problem:

I have two files: triangle.h,
triagle.c
I compiled the latter into triangle.obj using VC6.0, then added the
..obj and .h into my project, expecting them to work with other files.
but the most magic thing happened: if I called a function declared in
triangle.h from a .c file, it would work well, but if every line
codes remained the same with the file changed into an .cpp file, it
would tell that the function doesn't take right number of parameters.
the main part of the triangle.h is like this:

#ifdef ANSI_DECLARATORS
void triangulate(char *, struct triangulateio *, struct
triangulateio *,
struct triangulateio *);
void trifree(VOID *memptr);
#else /* not ANSI_DECLARATORS */
void triangulate();
void trifree();
#endif /* not ANSI_DECLARATORS */

I'm really confused with the ANSI_DECLARATORS, is it something
distinguishing between .c and .cpp?
I learned C++ as my first, and I know very little about C.

I will really appreciate if you offer some help. Thanks a lot!
 
D

dasjotre

I'm not sure whether it is proper to post it here, but I regard it at
least has something to do with C++.
Let me try to clarify my problem:

I have two files: triangle.h,
triagle.c
I compiled the latter into triangle.obj using VC6.0, then added the
.obj and .h into my project, expecting them to work with other files.
but the most magic thing happened: if I called a function declared in
triangle.h from a .c file, it would work well, but if every line
codes remained the same with the file changed into an .cpp file, it
would tell that the function doesn't take right number of parameters.
the main part of the triangle.h is like this:

#ifdef ANSI_DECLARATORS
void triangulate(char *, struct triangulateio *, struct
triangulateio *,
struct triangulateio *);
void trifree(VOID *memptr);
#else /* not ANSI_DECLARATORS */
void triangulate();
void trifree();
#endif /* not ANSI_DECLARATORS */

I'm really confused with the ANSI_DECLARATORS, is it something
distinguishing between .c and .cpp?
I learned C++ as my first, and I know very little about C.

I will really appreciate if you offer some help. Thanks a lot!

In old C a function declaration was no more than
a declaration of a name. that is, you could declare
function as void f() and then use it with arguments.
or: void f(a) where a is not typed and then use it
as you please. C++, and modern C I believe, are much
stricter. You have to type (and type) all arguments so
if a function is declared as void f() compiler
complains if you call it with arguments. The standard
body which deals with these issues is called ANSI.

I'm not sure how you got there but C++ is not
just C with classes. Post some code, particularly
the function theat troubles the compiler.
 
J

Jack Klein

I'm not sure whether it is proper to post it here, but I regard it at
least has something to do with C++.
Let me try to clarify my problem:

I have two files: triangle.h,
triagle.c
I compiled the latter into triangle.obj using VC6.0, then added the
.obj and .h into my project, expecting them to work with other files.
but the most magic thing happened: if I called a function declared in
triangle.h from a .c file, it would work well, but if every line
codes remained the same with the file changed into an .cpp file, it
would tell that the function doesn't take right number of parameters.
the main part of the triangle.h is like this:

#ifdef ANSI_DECLARATORS
void triangulate(char *, struct triangulateio *, struct
triangulateio *,
struct triangulateio *);
void trifree(VOID *memptr);
#else /* not ANSI_DECLARATORS */
void triangulate();
void trifree();
#endif /* not ANSI_DECLARATORS */

I'm really confused with the ANSI_DECLARATORS, is it something
distinguishing between .c and .cpp?
I learned C++ as my first, and I know very little about C.

I will really appreciate if you offer some help. Thanks a lot!

The macro ANSI_DECLARATORS is not part of either standard C or
standard C++. It is the type of macro that was often used in the
early days after the first C standard in 1989.

If you used a C compiler that supported the "newfangled" use of
prototypes, you would define this macro and the compiler would see the
prototype declarations for the functions. If you had a pre-standard
compiler that did not handle prototypes, you left the macro undefined
and the compiler only saw the old style declarations that did not
include information on the parameters.

C++ has always required prototype style function declarations, and C
has allowed them for 17 years. For C++ usage, you should either edit
the files to remove the macro and only leave the function declarations
that include argument types, or just define the macro before including
the header, like this:

#define ANSI_DECLARATORS
 
V

velvetyuan

thanks a lot. that works:)
Jack said:
The macro ANSI_DECLARATORS is not part of either standard C or
standard C++. It is the type of macro that was often used in the
early days after the first C standard in 1989.

If you used a C compiler that supported the "newfangled" use of
prototypes, you would define this macro and the compiler would see the
prototype declarations for the functions. If you had a pre-standard
compiler that did not handle prototypes, you left the macro undefined
and the compiler only saw the old style declarations that did not
include information on the parameters.

C++ has always required prototype style function declarations, and C
has allowed them for 17 years. For C++ usage, you should either edit
the files to remove the macro and only leave the function declarations
that include argument types, or just define the macro before including
the header, like this:

#define ANSI_DECLARATORS
 
V

velvetyuan

thanks for your explanations. I've learnt a lot from them. I think i'm
really a little boy in this huge world of programming.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top