Redian新闻
>
用c怎么实现generic stack (转载)
avatar
用c怎么实现generic stack (转载)# Programming - 葵花宝典
R*n
1
最近几次出入噪声很大的场所,事后觉得耳朵不舒服,不知道会不会有听力损失。想问
一下大家配耳塞是到医院找医生配,还是到店里去配啊?
谢谢!
avatar
b*n
2
之前就据说挺好看的。
刚看到拿了金球奖了。
avatar
s*n
3
网上看到这样一段话, 山是指仙吗?
“山、医、命、卜、相”。其中“相”的层次最低,因为看的是最表面之相,由“相”
到“卜”递进一层,可以龟板、蓍草等卜卦预测未来。再进一层到算“命”,即按人的
生辰八字等已知信息预测人一生的命运。到此为止,人的活动还基本上是挖掘事实,还
不能解决问题。只有到了“医”的层次,人才不是被动地面对看得见和看不见的事实和
问题,而是进入积极主动解决问题的阶段。而由“医”再上一层,就是“山”。为何是
山?就是这境界是山上才可修成的,一言以蔽之,山乃神矣!故中国的仙字就由山和人
构成
avatar
a*n
4
touch pro要装什么东西才能看中文小说? 我现在用islio看中文都是乱码,小说的中文
名字倒是不乱码.
avatar
l*d
5
【 以下文字转载自 JobHunting 讨论区 】
发信人: lwsOsgvd (lwsOsgvd), 信区: JobHunting
标 题: 用c怎么实现generic stack
发信站: BBS 未名空间站 (Tue Apr 24 16:42:43 2012, 美东)
用设计个stack,要求是The stack should be able to take as input a wide
variety of data types: it could range from byte sized to an n-byte sized
structure。
刚好在PIE书里面看到这个
typedef struct Element {
struct Element *next;
void *data;
} Element;
不知道算不算达到要求。
多谢!
avatar
c*s
6
不需要找医生,直接去超市买.注意,耳塞戴半年以后耳朵内部皮肤会开始觉得敏感,有时
耳朵周围会觉得有点麻木,不戴耳塞之后会好转.

【在 R**********n 的大作中提到】
: 最近几次出入噪声很大的场所,事后觉得耳朵不舒服,不知道会不会有听力损失。想问
: 一下大家配耳塞是到医院找医生配,还是到店里去配啊?
: 谢谢!

avatar
r*g
7
这种LGBT的戏不看也罢。尤其不要让小孩子看到。
avatar
c*o
8
修仙 或 堪舆
avatar
l*e
9
找版上雅黑字体安装包
avatar
d*n
10
generic C 有两类,一类是 void *, 但是有转换消耗。
另一类是 C marco,但是难debug
对于你的要求,可变的size,当然要用C marco
///file gstack.c
#define _STACK_STRUCT(STACKNAME, DATATYPE) \
typedef struct STACKNAME { \
struct STACKNAME * next;\
DATATYPE value;\
}STACKNAME##_t;
#define __STACK_POP(STACKNAME, DATATYPE ) \
void pop_##STACKNAME( STACKNAME##_t *node ) \
{ \
;\
}
#define __STACK_PUSH(STACKNAME, DATATYPE ) \
void push_##STACKNAME( STACKNAME##_t *node ) \
{ \
;\
}
///define more functions here
#define DEFINE_STACK(STACKNAME, DATATYPE) \
_STACK_STRUCT(STACKNAME, DATATYPE ) \
__STACK_POP(STACKNAME,DATATYPE)\
__STACK_PUSH(STACKNAME,DATATYPE)
///install more function declarations
///example usage
DEFINE_STACK(lwsOsgvd , int)
gcc gstack.c -E
# 1 "gstack.c"
# 1 ""
# 1 ""
# 1 "gstack.c"
# 24 "gstack.c"
typedef struct lwsOsgvd { struct lwsOsgvd * next; int value;}lwsOsgvd_t;
void pop_lwsOsgvd( lwsOsgvd_t *node ) { ; }
void push_lwsOsgvd( lwsOsgvd_t *node ) { ; }
avatar
R*n
11
哦,谢谢。
医生给配的会不会更专业一些,不会有敏感之类的问题?
avatar
w*i
12
喜剧类去年最好的剧,满满的爱。每个成员的生活方式在传统守旧的家庭观看来都是笑
话和羞耻。但本质上这个家庭并没有什么不同,爱自己家人,就要让他们真正快乐,而
不是承受各种世俗的压力
avatar
n*e
13
给个链接不~

【在 l*****e 的大作中提到】
: 找版上雅黑字体安装包
avatar
X*r
14
一个栈能不能压入异质的数据类型,是根本不同的要求,没法比较。看原题的意思应该
是要能压入异质的数据类型的,不是像你这样的。
而且这个void *的转换消耗不知道是从何说起啊。

【在 d****n 的大作中提到】
: generic C 有两类,一类是 void *, 但是有转换消耗。
: 另一类是 C marco,但是难debug
: 对于你的要求,可变的size,当然要用C marco
: ///file gstack.c
: #define _STACK_STRUCT(STACKNAME, DATATYPE) \
: typedef struct STACKNAME { \
: struct STACKNAME * next;\
: DATATYPE value;\
: }STACKNAME##_t;
: #define __STACK_POP(STACKNAME, DATATYPE ) \

avatar
c*n
15
http://www.mitbbs.com/article_t/PDA/31225483.html

【在 a**********n 的大作中提到】
: touch pro要装什么东西才能看中文小说? 我现在用islio看中文都是乱码,小说的中文
: 名字倒是不乱码.

avatar
d*n
16
Void pointer can be flexibly converted into vary types with the cost of type
cast.
Also, the data structure size is not changing, but a two pointers: one is
the necessary next pointer, the other is datum.
here is the what I said "cost" from one of my favorite person's blog.
"We usualy use void* to implement generic containers in C. To do in this way
, we need to pay an overhead on retrieving data pointed by a void* pointer.
We often, but not always, need a function call for operations on void* data,
such as copying, comparing or hashing. This adds additional overhead on
speed. Furthermore, if the size of an object is small, we would rather put
the whole object in the container instead of wasting the memory for an
addition pointer: using void* may also bring memory overhead."
Using void* in Generic C Programming may be Inefficient depends on how heavily type cast called. Instead, C macro is
part of the idea how c++ implement its generic template mechanism.
avatar
X*r
18
cast指针本身没有什么额外消耗,除了多打几个字。存指针而不是数据本身的消耗你的
宏实现里不是一样也有吗?

type
way
.
data,

【在 d****n 的大作中提到】
: Void pointer can be flexibly converted into vary types with the cost of type
: cast.
: Also, the data structure size is not changing, but a two pointers: one is
: the necessary next pointer, the other is datum.
: here is the what I said "cost" from one of my favorite person's blog.
: "We usualy use void* to implement generic containers in C. To do in this way
: , we need to pay an overhead on retrieving data pointed by a void* pointer.
: We often, but not always, need a function call for operations on void* data,
: such as copying, comparing or hashing. This adds additional overhead on
: speed. Furthermore, if the size of an object is small, we would rather put

avatar
d*n
19
DATATYPE can be anything , pointer or a complex data struct.
And there is not cast need in my Code.
Indeed, Type Cast DOES cost overhead. And if constantly doing that, codes
will become bitterly disgusting for debugging by programmers. For example,
the "undefined member" issues will happen alot when programmer forget the
original definition of the data type need to be converted.
Also, you already conclude yourself that "除了多打几个字". If comparing with
easiness of developing, more typing means more mistakes to occur.
Moreover, Readability decrease in some degree.
I am not showing how extremely I hate the void * approach. Actually,
in some of my project, I do use void * because It is fast to do. If given
more time, I would rather invent
a generic C lib using C macro.
Back to his question, as far as I understand, Using C macro is the way to
success it. unless I misunderstand the specifications ~~

【在 X****r 的大作中提到】
: cast指针本身没有什么额外消耗,除了多打几个字。存指针而不是数据本身的消耗你的
: 宏实现里不是一样也有吗?
:
: type
: way
: .
: data,

avatar
X*r
20
I think you misunderstood the question.

with

【在 d****n 的大作中提到】
: DATATYPE can be anything , pointer or a complex data struct.
: And there is not cast need in my Code.
: Indeed, Type Cast DOES cost overhead. And if constantly doing that, codes
: will become bitterly disgusting for debugging by programmers. For example,
: the "undefined member" issues will happen alot when programmer forget the
: original definition of the data type need to be converted.
: Also, you already conclude yourself that "除了多打几个字". If comparing with
: easiness of developing, more typing means more mistakes to occur.
: Moreover, Readability decrease in some degree.
: I am not showing how extremely I hate the void * approach. Actually,

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。