Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does pycparser reads the header files listed in includes in C code files?

I am trying to parse a C file using pycparser. I am curious to know that while pre-processing the C file does the pycparser reads only those library files which are provided in fake lib folder(if you provide the path of fake lib in cpp_args) or it also reads from the location mentioned in include statements, such as-
in line below

#include<folder1/folder2/xyz.h>  

where will the pycparser search for xyz.h will it only be in FAKE LIB folder?

like image 981
user3705462 Avatar asked Dec 31 '25 17:12

user3705462


1 Answers

It will search other directories than the fake folder. If you look in the file pycparser/__init__.py, you'll find a function called preprocess_file which invokes the C preprocessor on your input file and puts the resulting output in a string, which it then passes to the next function called parse_file. The code in each of these functions is fairly clear and well-commented, so give it a read and see if it makes sense.

The fake folder is included only for standard library headers like stdlib.h, stdio.h and so forth. Those headers often contain non-portable compiler-specific extensions; chances are, you'll only need to know that there's a function printf(...) in order to be able to parse your code.

like image 96
Daniel Shapero Avatar answered Jan 02 '26 05:01

Daniel Shapero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!