Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: ingpjb on April 20, 2012, 10:41:49 am

Title: Missing includes / Preprocessor directive error ?
Post by: ingpjb on April 20, 2012, 10:41:49 am
Hello All,

I'm writing code in ANSI C and have a few header-files with (amongst other things) my function prototypes.
In one header-file I use a precompiler directive like :

#ifdef INTERFACE_LISTENER
  use function 1
#else
  use function 2
#endif // INTERFACE_LISTENER

I DO NOT specify INTERFACE_LISTENER at compile-time and so would expect function 2 in my global functions and code-completion.
BUT : I don't get function 2 (as well as function 1 by the way)
When I comment out to the following :

//#ifdef INTERFACE_LISTENER
//  use function 1
//#else
  use function 2
//#endif // INTERFACE_LISTENER

I get function 2 as I would like. (But that is very obvious .............!)

Can anyone give me a clou about the failing 'switch' for the precompiler ?

Regards,

PeTer

Title: Re: Missing includes / Preprocessor directive error ?
Post by: Freem on April 20, 2012, 02:03:20 pm
I think I remember that rules said that this is not a general programming board.

Going on such a forum to ask your question will probably result in more useful answers. But when you will do that, do not forget to give true code, not pseudo code, because here, people can not see where is your error.
Another thing will be to specify your compiler and the error you have.
Title: Re: Missing includes / Preprocessor directive error ?
Post by: jarod42 on April 20, 2012, 02:25:21 pm
Code
#undef SOME_MACRO
#ifdef SOME_MACRO
  void function_1a() {}
  void function_1b();
#else
  void function_2a() {}
  void function_2b();
#endif // SOME_MACRO

void foo()
{
    function_|Ctrl+Space
}

code completion doesn't show any function_2 (but for me, it shows the function_1).
and in the item list that shows function names, function_2a is not present (but I have function_1a)

Title: Re: Missing includes / Preprocessor directive error ?
Post by: stahta01 on April 20, 2012, 02:31:43 pm
I think I remember that rules said that this is not a general programming board.

Going on such a forum to ask your question will probably result in more useful answers. But when you will do that, do not forget to give true code, not pseudo code, because here, people can not see where is your error.
Another thing will be to specify your compiler and the error you have.

The question above is very likely Code::Blocks related.
As  it is about Code Completion and maybe symbol browser.

NOTE: My only suggestion is trying a nightly build and see if the problem goes away.

FYI: Without a Code::Blocks version information this post is more likely to be ignored.

Tim S.
Title: Re: Missing includes / Preprocessor directive error ?
Post by: Freem on April 20, 2012, 02:47:38 pm
Err... sorry, it seem I am a bit tired... My apologies
Title: Re: Missing includes / Preprocessor directive error ?
Post by: Jenna on April 20, 2012, 04:17:58 pm
I just tested it in the actual version from my repo with "Settings -> Editor... -> Code completion -> C/C++ parser -> Parse preprocessor directives" enabled, and it works correctly here.
It does not respect defines made in the projects "Build options", just defines inside the code.
Title: Re: Missing includes / Preprocessor directive error ?
Post by: ingpjb on April 20, 2012, 04:30:03 pm
Well,

I've checked my code-completion settings and they are correct ! But still, my Code::Blocks does not parse the header file correct.

The original code is :

#ifdef INTERFACE_LISTENER
    extern void pjb_if_init(PjbIf* handleStatemachine_cy* statemachine, EventSet* eventSet);
    extern void pjb_if_set_listener(PjbIf* handle, handleEvent handleEventPtr);
    extern void pjb_if_raiseEventPjbIf* handle, _Event* event);
#else
    extern void pjb_if_init(PjbIf* handle, Statemachine_cy* statemachine, EventSet* eventSet, EventPool* eventPool);
    extern sc_boolean pjb_if_is_entryOn_raised(PjbIf* handle );
    extern sc_boolean pjb_if_is_exitOn_raised(PjbIf* handle );
    extern sc_boolean pjb_if_is_entryOff_raised(PjbIf* handle );
    extern sc_boolean pjb_if_is_exitOff_raised(PjbIf* handle );
    extern void pjb_if_raise_switchOn(PjbIf* handle);
    extern void pjb_if_raise_switchOff(PjbIf* handle);
    extern void pjb_if_raise_leave(PjbIf* handle);
#endif // INTERFACE_LISTENER

Even when NOT using INTERFACE_LISTENER the parser does not show the functions between #else & #endif .....  ???
When commenting out to the following :

//#ifdef INTERFACE_LISTENER
//    extern void pjb_if_init(PjbIf* handleStatemachine_cy* statemachine, EventSet* eventSet);
//    extern void pjb_if_set_listener(PjbIf* handle, handleEvent handleEventPtr);
//    extern void pjb_if_raiseEventPjbIf* handle, _Event* event);
//#else
    extern void pjb_if_init(PjbIf* handle, Statemachine_cy* statemachine, EventSet* eventSet, EventPool* eventPool);
    extern sc_boolean pjb_if_is_entryOn_raised(PjbIf* handle );
    extern sc_boolean pjb_if_is_exitOn_raised(PjbIf* handle );
    extern sc_boolean pjb_if_is_entryOff_raised(PjbIf* handle );
    extern sc_boolean pjb_if_is_exitOff_raised(PjbIf* handle );
    extern void pjb_if_raise_switchOn(PjbIf* handle);
    extern void pjb_if_raise_switchOff(PjbIf* handle);
    extern void pjb_if_raise_leave(PjbIf* handle);
//#endif // INTERFACE_LISTENER

then the functions show up in the symbol listing and codecompletion ..... which is obvious ....

Any ideas anyone ?

PeTer
Title: Re: Missing includes / Preprocessor directive error ?
Post by: MortenMacFly on April 20, 2012, 04:40:59 pm
Any ideas anyone ?
Enable macro parsing in the CC options.
Title: Re: Missing includes / Preprocessor directive error ?
Post by: Jenna on April 20, 2012, 05:09:40 pm
Any ideas anyone ?
Enable macro parsing in the CC options.
Works here without it.

@ingpjb:

which version of C::B do you use ?
Title: Re: Missing includes / Preprocessor directive error ?
Post by: ingpjb on April 21, 2012, 03:15:47 pm
@ jens

Hi jens,

I'm currently using version 10.05 (Build: May 27 2010, 11:01:50 - wx2.8.10 (Linux, unicode) - 32 bit) on a Debian machine .....

Regards,

PeTer