Author Topic: Missing includes / Preprocessor directive error ?  (Read 8044 times)

Offline ingpjb

  • Single posting newcomer
  • *
  • Posts: 3
Missing includes / Preprocessor directive error ?
« 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


Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: Missing includes / Preprocessor directive error ?
« Reply #1 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.

Offline jarod42

  • Multiple posting newcomer
  • *
  • Posts: 82
Re: Missing includes / Preprocessor directive error ?
« Reply #2 on: April 20, 2012, 02:25:21 pm »
Code: [Select]
#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)


Offline stahta01

  • Lives here!
  • ****
  • Posts: 6799
    • My Best Post
Re: Missing includes / Preprocessor directive error ?
« Reply #3 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.
« Last Edit: April 20, 2012, 02:34:13 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: Missing includes / Preprocessor directive error ?
« Reply #4 on: April 20, 2012, 02:47:38 pm »
Err... sorry, it seem I am a bit tired... My apologies

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Missing includes / Preprocessor directive error ?
« Reply #5 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.

Offline ingpjb

  • Single posting newcomer
  • *
  • Posts: 3
Re: Missing includes / Preprocessor directive error ?
« Reply #6 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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9592
Re: Missing includes / Preprocessor directive error ?
« Reply #7 on: April 20, 2012, 04:40:59 pm »
Any ideas anyone ?
Enable macro parsing in the CC options.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Missing includes / Preprocessor directive error ?
« Reply #8 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 ?

Offline ingpjb

  • Single posting newcomer
  • *
  • Posts: 3
Re: Missing includes / Preprocessor directive error ?
« Reply #9 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