Home > Enterprise >  Viewing the standard library implementations
Viewing the standard library implementations

Time:01-10

I'm using VS-Code on windows. And I'm using rust-analyzer extension. It also works for C/C . When I want to view the implementation of a standard library function, it takes me to the function's declaration.

For example:

When I try to view the malloc function, it takes me to

_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
_ACRTIMP _CRTALLOCATOR _CRT_JIT_INTRINSIC _CRTRESTRICT _CRT_HYBRIDPATCHABLE
void* __cdecl malloc(
    _In_ _CRT_GUARDOVERFLOW size_t _Size
    );

this is located in corecrt_malloc.h file. But this is just a declaration. I'm unable to find the actual implementation for any std function. I don't want to go and search files manually. Is there an easier way to do this?

Note: findstr doesn't work for me. If I type, for example, malloc, it finds every malloc call.

CodePudding user response:

The actual definition of the function is almost certainly not there. It is compiled and distributed inside the C runtime library.

CodePudding user response:

If you have the Windows SDK installed, look for the file (change the version if necessary):

C:\Program Files (x86)\Windows Kits\10\Source\10.0.22000.0\ucrt\heap\malloc.cpp

You will notice malloc calls _malloc_base, which is in malloc_base.cpp in the same directory. _malloc_base then calls HeapAlloc. And since this one is part of Windows system DLLs (namely kernel32.dll), I fear you won't find its source code.

  •  Tags:  
  • c c
  • Related