Source Code of C/C++ Functions

source code of c/c++ functions

You could check out a copy of glibc, which will have the source code for all C functions in the C standard library. That should be a good starting place.

how to check c standard library function source code in eclipse

The source code for some standard library implementations, such as glibc, are available online, and you can look up its fgets() code. But the source code isn't typically installed on a development PC unless you're building your own toolchain for some reason (e.g., a cross-compiler). In fact, portions of the source code are often written in assembly. Only the compiled object files are usually installed on development / target PCs. Therefore, your IDE doesn't have access to the source and can't show it to you. Other standard libraries like Microsoft's MSVCRT are proprietary and the source code is not available, only the compiled library. You can always disassemble that of course, but the output is not likely to be very useful to you.

In general most (not all!) C/C++ programmers treat standard library functions as black boxes and rely on good reference documentation to understand their behavior.

How to get the C/C++ source code of the a secondary function of R?

The searchable R source code at https://github.com/wch/r-source is really useful for this:

  • First we can look for the read.table definition
  • The actual data reading is done by the scan function which in the end uses

    .Internal(scan(file, what, nmax, sep, dec, quote, skip, nlines,
    [...]
  • Now scan is mapped to do_scan

So here you are: The underlying C implementation for read.table can be found in src/main/scan.c, starting with the function do_scan.

C++ __builtin_* functions source codes

I want to learn how can I find

First become acquainted with the language you are working with - learn C and C++ programming languages. Learn about the tools like git and autotools and the environment around these programming languages. Become familiar with the tool set needed browsing files - at least grep, but I recommend it's (way) faster alternatives - "the silver searcher" ag or ack, but be aware of tools like ctags or GNU Global.

Then research. GNU projects are available open source - it's very easy to find source code of GNU projects, nowadays they are even mirrored on github.

Then it's just a "feeling" or "experience". Surely a project will have builtins functions in a file named "builtins.c" or something similar. Be curious, reasonable and inventive. If you would want to add a builtin function to a codebase, where would you put it? Become familiar with the project structure you are working with. And expect big and old projects to have stuff scattered all over the place.

First I find gcc sources with builtins.def (BUILT_IN_CBRT, "cbrt", and some references of BUILT_IN_CBRT in builtins.c.

After cloning the gcc repository I scan for BUILT_IN_CBRT macro name. Browsing the code leads me to CASE_CFN_CBRT macro name, which leads me to fold-const-call.c:

CASE_CFN_CBRT:
return do_mpfr_arg1 (result, mpfr_cbrt, arg, format);

By the name of the file fold-const-call.c I suspect this part of code is taken only when folding a constant call.

From there I can browse google about mpfr_cbrt symbol, which leads me to GNU MPFR library. I find clone of MPRF library on github and search for a file named cbrt, I find cbrt.c with mpfr_cbrt() sources with the source of cbrt within MPRF library. This is the code that will be called and will compute cbrt of a number when __builtin_cbrt is folded inside a constant expression, I suspect.

When not in constnat expression, I suspect that [fold_const_call_ss]https://code.woboq.org/gcc/gcc/fold-const-call.c.html#_ZL18fold_const_call_ssP10real_value11combined_fnPKS_PK11real_format) is not called at all, instead some fold_const_* function returns to gcc that the expression cannot be constantly folded so a call to the actual cbrt() standard function is generated.

Where can I get the source code of the C standard functions in gcc/clang etc?

You can try to get the source code of glibc or any similar C library implementation. That should have the code you are looking for. You can also browse the source code of glibc online.

As for the reasoning, its basic "You dont see what you dont need to see" reasoning. There is no need to see the implementation, just the interface to the library.

Where can I find the source code for all the C standard libraries?

PJ Plauger wrote a book about the standard C library. Includes references from the (now dated) standard, and source code.



Related Topics



Leave a reply



Submit