1

In the following header file i declared some functions:

    #ifndef _MY_INT_FUNCTIONS_H_
    #define _MY_INT_FUNCTIONS_H_



    int intFcn (const void *key, size_t table_size);
    void intPrint (const void *key);
    int intCompare (const void *key1, const void *key2);


    #endif // _MY_INT_FUNCTIONS_H_

but i get a compilation error saying:

"expected declaration specifiers or ‘...’ before ‘size_t’"

regarding the int intFcn function.

im using eclipse INDIGO version.

help anyone?

3
  • I think you should include stdlib.h Commented Aug 24, 2011 at 14:24
  • Another example of the horrific and inappropriate error messages most C compilers issue. Why doesn't the compiler just say "Unrecognized type" instead? Commented Aug 24, 2011 at 14:27
  • @Blagovest Buyukliev : because of the way parsers work. The parser expects something, but sees something else, so it gives an error stating exactly that. Nicer error messages generally mean more complex parsers. Given that C++ parsers are already quite complex (due to the nature of the C++ grammar), that is a difficult task. I agree having nicer error messages would be interesting, but it's hard to achieve. Commented Aug 24, 2011 at 14:36

2 Answers 2

4

In C++ size_t is declared in the <cstddef> header in the std namespace.

#include <cstddef>

int intFcn (const void *key, std::size_t table_size);

In C (and in C++ too), it's declared in <stddef.h>:

#include <stddef.h>

int intFcn (const void *key, size_t table_size);
Sign up to request clarification or add additional context in comments.

Comments

4

For size_t, you need to :

#include <stddef.h>   // in C

or :

#include <cstddef>    // in C++

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.