Author Topic: Auto-completion compatible C standard library  (Read 1713 times)

Offline Hendi48

  • Single posting newcomer
  • *
  • Posts: 1
Auto-completion compatible C standard library
« on: August 25, 2016, 07:06:14 pm »
Hello,

I recently started using Code::Blocks 16.01 after my C project became too big to develop comfortably in Notepad++. One of the features that are really useful in NP++ is that it's aware of the C standard library and provides function prototypes with argument types and names when typing "memset(" etc.
Now, to get this type of behaviour in C::B, I figured I had to add the include folder to the compiler search path (I'm using GCC 6.1.0 from msys2/mingw). So far, so good. What it shows me now is this: "char* memset()". I guess it fails to properly parse the header, since it's written in a slightly convoluted way...
Code: [Select]
_PTR _EXFUN(memmove,(_PTR, const _PTR, size_t));
_PTR _EXFUN(memset,(_PTR, int, size_t));
char *_EXFUN(strcat,(char *__restrict, const char *__restrict));
I also tried MSVC headers, but there it's even worse with 50 annotations for every function.

Is there any easy way to get IDE-friendly headers, preferably even with argument names?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Auto-completion compatible C standard library
« Reply #1 on: September 04, 2016, 09:14:26 am »
I think CC can handle such kinds of macros, if you search our forum by "_EXFUN", you will see some discussions. Such as: Is it possible for the parser to support newlib prototypes?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Auto-completion compatible C standard library
« Reply #2 on: September 04, 2016, 09:50:08 am »
Try to put those content in the main.c file of your project. (Note main.c is the only source file in your project).
Code: [Select]
#define _EXFUN(name, proto) __cdecl name proto

FILE * _EXFUN(fopen, (const char *__restrict _name, const char *__restrict _type));

Now, after that, type "fopen", and see whether it will prompt the correct auto completion. It works fine here in my C::B.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.