自动打印struct [英] print struct automaticly

查看:70
本文介绍了自动打印struct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须打印几个大的结构来打印屏幕。

我想知道它们是否是一个自动执行此工具的工具


struct A


{

int i;

char * s;

}

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


< blockquote> 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 automaticly

struct A

{
int i;
char * s;
}

A a;

it will print it''s contents :
i=0
s="somestring
etc;
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 automaticly

struct A

{
int i;
char * s;
}

A a;

it will print it''s contents :
i=0
s="somestring

No. There is no such thing in ISO C, and if you want to write one
yourself you''ll have a nice task on your hands, too. For starters, there
is no way in ISO C to let your program get at the names (rather than the
values) of a random struct member - except for remembering it from the
start, which rather puts a dent in the generality of the tool.

Richard


Richard 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 automaticly

struct A

{
int i;
char * s;
}

A a;

it will print it''s contents :
i=0
s="somestring


No. There is no such thing in ISO C, and if you want to write one
yourself you''ll have a nice task on your hands, too. For starters, there
is no way in ISO C to let your program get at the names (rather than the
values) of a random struct member - except for remembering it from the
start, which rather puts a dent in the generality of the tool.

A sufficiently cunning tool -- or sufficiently transparent markup in
the 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 the
struct(s) should be printed. Generally speaking, I''d write the
struct-printer function as part of the cluster of functions that
belong with the struct [1]; since large structs from smaller structs
grow, I wouldn''t be faced with the "oh /frelling/ tedium, I have
to write a print function for a 117-element struct /now/!". (Also
I 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 a
simple string description, send one to bed with a cup of cocoa
and 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 automaticly

You may like to look at some platform-specifics (like the STABS and
DWARF debugging formats) to see if they are appropriate, but that''s not
part of the standard C language.

For general purposes, Chris Dollin''s suggestion seems most appropriate.


这篇关于自动打印struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆