简体   繁体   English

如何找出声明 C 结构的位置?

[英]How to find out where a C struct is declared?

I am trying to add logging to the web proxy Polipo and as part of this need to log the url request in the following function following line :我正在尝试将日志记录添加到 Web 代理 Polipo,作为其中的一部分,需要在以下函数中记录 url 请求:

httpClientRequest(HTTPRequestPtr request, AtomPtr url)

From compilation I see that AtomPtr is a struct of type _Atom but I cannot find where this is defined so that I can reference the text of the url in a log statement.从编译中我看到 AtomPtr 是_Atom类型的结构,但我找不到它的定义位置,以便我可以在日志语句中引用 url 的文本。 What is the canonical method of looking up struct definitions in C code?在 C 代码中查找结构定义的规范方法是什么?

you can search AtomPtr like this and see where AtomPtr is defined您可以像这样搜索AtomPtr并查看 AtomPtr 的定义位置

typedef struct _Atom {
    unsigned int refcount;
    struct _Atom *next;
    unsigned short length;
    char string[1];
} AtomRec, *AtomPtr;

Unfortunately, as far as I know, you cannot do this from the source code in C.不幸的是,据我所知,你不能从 C 的源代码中做到这一点。
If you are working on Linux, and if your sources are all in the src/ directory:如果您在 Linux 上工作,并且您的源代码都在src/目录中:

$ find src/ -name ".*\.h" | xargs grep -e "struct _Atom"

如果你在 Linux 上工作,那么 grep 当前目录中的struct关键字以查看它在文件中的定义。

I was able to look up the definition of a structure MenuType by我能够通过以下方式查找结构 MenuType 的定义

grep -Rwn --include \*.h "struct MenuType"

This post helped me. 这篇文章帮助了我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 结构的定义应该在哪里用C声明? .c或.h? - Where should be the definition of a struct be declared in C? .c or .h? 使用稍后声明的C结构 - using C struct that is declared later 如何在另一个.c文件中使用前向声明的struct数据? - How to use forward declared struct data in another .c file? C:如何使用在 function A 中声明和定义的结构,在另一个 function B 中 - C : How to use a struct, declared and defined in function A, in another function B 如何使用模板化的C ++结构定义C-forward声明的不透明结构 - How to define C-forward declared opaque struct with a templated C++ struct struct vop_vector在哪里声明? - Where is struct vop_vector declared? typedef的struct c,如何访问在typedef中声明为指针的struct实例? - typedef'ed struct c, how to access instances of struct which is declared as a pointer in typedef? 如何查找给定C函数及其内部声明的变量的分配内存(地址及其大小)? - How do I find out the allocated memory (both the address and its size) for a given C function and the variables declared inside it? 将前向声明的C-struct定义为C ++ - struct - Define forward declared C-struct as C++-struct 即使未声明在C中使用结构指针 - Using struct pointers in C even if they are not declared
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM