A a; 它会打印出来的内容: i = 0 s =" somestring 等; Thanx。 Kat。 解决方案 ka*****@gmail.com 写道: 我必须打印几个大型结构来打印屏幕。 我想知道是否可以自动执行这样的工具 结构A { int i; char * s; } A a; 它会打印出来的内容: i = 0 s =" somestring No.在ISO C中没有这样的东西,如果你想要wr你自己也会有一个很好的任务,你自己也有一个很好的任务。对于初学者来说, 在ISO C中无法让你的程序得到一个随机结构成员的名字(而不是 值) - 除了记住它从 开始,这反而削弱了工具的普遍性。 Richard Richard Bos写道: ka ***** @ gmail.com 写道: >我必须打印几个大的结构来打印屏幕。我想知道是否有一个工具可以自动执行此操作/> 结构A { int i; char * s; } A a; i = 0 s =" somestring No.在ISO C中没有这样的东西,如果你想自己写一个 ,你也会有一个很好的任务。对于初学者来说, 在ISO C中无法让你的程序得到一个随机结构成员的名字(而不是 值) - 除了记住它从 开始,这反而削弱了工具的普遍性。 一个足够狡猾的工具 - 或者C / C 中足够透明的标记 - 可以从结构声明中生成打印代码, 是吗?一般吗? 当然,有关/ 结构中的项目应该打印的各种问题。一般来说,我会把 struct-printer函数写成 属于struct [1]的函数集群的一部分;由于较小结构的大结构增长,我不会面对哦/ frelling / tedium,我有 来写一个打印功能117元素结构/现在/! (另外 无论如何我都不会写一个扁平的117元素结构。) [1] EG打印一个,初始化一个,malloc一个, free(一个指针)一个, 测试其中两个是否相等/相似,从一个 简单的字符串描述中构造一个,用一杯可可发送一个到床上 和一本好书。 - Chris本周的投票:/ The Riddle-Master Hed / Dollin 花了很长时间,比最慷慨的估计要长得多。 - James White,/ Sector General / ka*****@gmail.com 写道: 我必须打印几个大的结构来打印屏幕。 我想知道他们是否可以自动执行这样的工具 您可能希望查看一些特定于平台的内容(如STABS和 DWARF调试格式)以查看它们是否合适,但是这不是 标准C语言的一部分。 对于一般用途,Chris Dollin的建议似乎是最合适的。 I have to print several large structs to print the screen.I was wondering if thers a tool to do so automaticlystruct A{int i;char * s;}A a;it will print it''s contents :i=0s="somestringetc;Thanx.Kat. 解决方案 ka*****@gmail.com wrote:I have to print several large structs to print the screen.I was wondering if thers a tool to do so automaticlystruct A{int i;char * s;}A a;it will print it''s contents :i=0s="somestringNo. There is no such thing in ISO C, and if you want to write oneyourself you''ll have a nice task on your hands, too. For starters, thereis no way in ISO C to let your program get at the names (rather than thevalues) of a random struct member - except for remembering it from thestart, which rather puts a dent in the generality of the tool.RichardRichard Bos wrote: ka*****@gmail.com wrote:>I have to print several large structs to print the screen.I was wondering if thers a tool to do so automaticlystruct A{int i;char * s;}A a;it will print it''s contents :i=0s="somestringNo. There is no such thing in ISO C, and if you want to write oneyourself you''ll have a nice task on your hands, too. For starters, thereis no way in ISO C to let your program get at the names (rather than thevalues) of a random struct member - except for remembering it from thestart, which rather puts a dent in the generality of the tool.A sufficiently cunning tool -- or sufficiently transparent markup inthe C code -- can generate the printing code from the struct declaration,yes? General enough?Of course there are all sorts of issues about /how/ the items in thestruct(s) should be printed. Generally speaking, I''d write thestruct-printer function as part of the cluster of functions thatbelong with the struct [1]; since large structs from smaller structsgrow, I wouldn''t be faced with the "oh /frelling/ tedium, I haveto write a print function for a 117-element struct /now/!". (AlsoI wouldn''t write a flat 117-element struct anyway.)[1] EG print one, initialise one, malloc one, free (a pointer to) one,test two of them for equality/similarity, construct one from asimple string description, send one to bed with a cup of cocoaand a good book.--Chris "this week''s vote: /The Riddle-Master of Hed/" Dollin"It took a very long time, much longer than the most generous estimates."- James White, /Sector General/ ka*****@gmail.com wrote:I have to print several large structs to print the screen.I was wondering if thers a tool to do so automaticlyYou may like to look at some platform-specifics (like the STABS andDWARF debugging formats) to see if they are appropriate, but that''s notpart of the standard C language.For general purposes, Chris Dollin''s suggestion seems most appropriate. 这篇关于自动打印struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 10:29