News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Missing includes / Preprocessor directive error ?

Started by ingpjb, April 20, 2012, 10:41:49 AM

Previous topic - Next topic

ingpjb

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


Freem

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.

jarod42

#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)


stahta01

#3
Quote from: 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.

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Freem

Err... sorry, it seem I am a bit tired... My apologies

Jenna

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.

ingpjb

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

MortenMacFly

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Jenna

Quote from: MortenMacFly on April 20, 2012, 04:40:59 PM
Quote from: ingpjb on April 20, 2012, 04:30:03 PM
Any ideas anyone ?
Enable macro parsing in the CC options.
Works here without it.

@ingpjb:

which version of C::B do you use ?

ingpjb

@ 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