备用功能名称 [英] alternate function names

查看:83
本文介绍了备用功能名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是语言和编程之间的界限,但我想

更多地关注语言标准问题,而不是编程问题,

所以我发帖这里。


我有许多函数,这些函数由宏前端结束,这些函数在函数调用方式上发生了一些变化。完成各种各样的事情,但是一个简单的例子是一个函数,它接受一个变量数字($ char $ *)的
并将所有字符串连接成一个单个

字符串,其中NULL是参数末尾的标记。宏的

前端添加了NULL,因此调用程序的细节不那么杂乱。


我一直在做的是给宏接口名称和

命名功能略有不同。我一直在说_在前面

的函数名称,我想放弃它。所以我有一个宏

喜欢:

#define strjoin(a ...)(_ strjoin(a,((const char *)(NULL))))

和一个函数定义如:

char * _strjoin(const char * s,...)


替代我'我正在看的是对于宏

和函数使用相同的名称,例如:

#define strjoin(a ...)((strjoin)(a ,((const char *)(NULL))))

和:

char *(strjoin)(const char * s,...)


这种方法有效,但我担心它可能引起的混乱。所以我想在这里做的就是看看有没有比上面显示的更好的替代方法来使用不同的

函数名。会有很多_人物帮助

避免冲突?喜欢也许:

#define strjoin(a ...)(_ _ strjoin __(a,((const char *)(NULL))))

和:

char * __ strjoin __(const char * s,...)


-

---------- -------------------------------------------------- -----------------

| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |

| (名字)在ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |

--------- -------------------------------------------------- ------------------

This question is borderline between language and programming, but I want to
focus more on the language standards issue, rather than the programming issue,
so I am posting here.

I have a number of functions which are front-ended by macros which make some
changes in the way the functions are called. There are various things being
done, but one simple example would be a function that takes a variable number
of (const char *) arguments and joins all the strings together into a single
string, where a NULL is the sentinel at the end of the arguments. The macro
front end adds that NULL so the calling program is less cluttered with detail.

What I have been doing with this is giving the macro the interface name and
naming the function slightly different. I have been putting a "_" in front
of the function name, which I want to get away from doing. So I have a macro
like:
#define strjoin(a...) (_strjoin(a,((const char*)(NULL))))
and a function definition like:
char *_strjoin(const char *s,...)

The alternative I''m looking at is to just use the same name for both macro
and function, like:
#define strjoin(a...) ((strjoin)(a,((const char*)(NULL))))
and:
char *(strjoin)(const char *s,...)

This approach works, but I''m worried about confusion it may cause. So what I
want to do here is see if there is a better alternative to using a different
function name than the one shown above. Would lots of "_" characters help
avoid conflicts? Like maybe:
#define strjoin(a...) (__strjoin__(a,((const char*)(NULL))))
and:
char *__strjoin__(const char *s,...)

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------

推荐答案

Phil ...

坦率地说,我宁愿编码NULL;如果我是一个维护者,那么
更愿意看到NULL,而不是花时间迷惑宏。


BTW,标识符以下划线开头或带有 ; STR"是

保留。由于这个原因,我的多字符串连接符以strs()开头,而

变为rtss()。 ) - :


-

Morris Dovey(WB0YEF)

美国爱荷华州西得梅因
$ b $ rel=\"nofollow\" href=\"http://www.iedu.com/c\" target=\"_blank\"> http://www.iedu.com/c 上的$ b C链接

读我的嘴唇:苹果离树不远。

Phil...

Frankly, I''d rather code the NULL; and if I were a maintainer I
would prefer to see the NULL than spend time puzzling over a macro.

BTW, identifiers beginning with underscores or with "str" are
reserved. My multi-string concatenator started out as strs() and
became rtss() for this reason. )-:

--
Morris Dovey (WB0YEF)
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn''t fall far from the tree.


2003年12月9日星期二13:09 :56 -0600 Morris Dovey< mr ***** @ iedu.com>写道:


|坦率地说,我宁愿编码NULL;如果我是维护者,我将获得
|我宁愿看到NULL而不是花时间迷惑一个宏。


我持相反观点。但是如果我为函数本身找到一个合适的替代名称

,你可以编写直接函数调用并使用

NULL。我发现这很痛苦。我的图书馆旨在消除编程中的许多痛苦,同时仍然允许我进行C级访问。

|顺便说一句,标识符以下划线开头或以str开头。是

|保留。我的多字符串连接符以strs()和

|开头因此而成为rtss()。 ) - :


我已经拥有大量的字符串函数。但有一件事他们都有b $ b确实有,他们以str_开头。 (我之前发布的示例没有

显示该库的真实姓名)。我认为为函数设置

可识别且可理解的名称更为重要。我没有

猜到rtss()甚至在你没有这么说的情况下是什么。那么你是什么做了什么,只需要反转str到rts对于一切?


在C99的最后一个草案中的脚注146显示了

保留的标识符的使用(7.1.3)。它正在做的是隐藏保留的用法。因此,b $ b似乎意味着这些预订不适用于幕后。

但目前还不清楚这是实施C还是实施某些东西

in C.


-

----------------- -------------------------------------------------- ----------

| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |

| (名字)在ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |

--------- -------------------------------------------------- ------------------
On Tue, 09 Dec 2003 13:09:56 -0600 Morris Dovey <mr*****@iedu.com> wrote:

| Frankly, I''d rather code the NULL; and if I were a maintainer I
| would prefer to see the NULL than spend time puzzling over a macro.

I hold the opposite view. But if I were to find a suitable alternate name
for the function itself, you could code direct function calls and use the
NULL. I find it a big pain. My library is intended to remove many of the
pains in programming while still giving me C level access.
| BTW, identifiers beginning with underscores or with "str" are
| reserved. My multi-string concatenator started out as strs() and
| became rtss() for this reason. )-:

I already have a huge number of string functions. But one thing they all
do have is they begin with "str_" (the example I previously posted did not
show a real name from that library). I think it is more important to have
recognizable and understandable names for functions. I would not have
guessed what rtss() is even about without you saying so. So what did you
do, just reverse "str" to "rts" for everything?

Footnote 146 in the last draft for C99 shows usage of an identifier that
is reserved (7.1.3). What it''s doing is hiding the reserved usage. So it
would seem to imply that such reservations do not apply behinds the scenes.
But it''s unclear if this is an implemention C, or an implemention of something
in C.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------


< ph ************** @ ipal.net>写道:
<ph**************@ipal.net> wrote:
On Tue,09 Dec 2003 13:09:56 -0600 Morris Dovey< mr ***** @ iedu.com>写道:
|顺便说一句,标识符以下划线开头或以str开头。是
|保留。我的多字符串连接符最初是strs()和
|因此而成为rtss()。 ) - :

我已经拥有大量的字符串函数。但他们都有的一件事是他们以str_开头。 (我之前发布的示例没有显示该库中的真实姓名)。
On Tue, 09 Dec 2003 13:09:56 -0600 Morris Dovey <mr*****@iedu.com> wrote:
| BTW, identifiers beginning with underscores or with "str" are
| reserved. My multi-string concatenator started out as strs() and
| became rtss() for this reason. )-:

I already have a huge number of string functions. But one thing
they all do have is they begin with "str_" (the example I previously
posted did not show a real name from that library).




实际上,str_没关系str前缀仅在以小写字母跟随

时保留。


保留标识符包括:


是[abcdefghijklmnopqrstuvwxyz] *

到[abcdefghijklmnopqrstuvwxyz] *

cerf

cerfc

cexp2

cexpm1

clog10

clog1p

clog2

clgamma

ctgamma

cerf [fl]

cerfc [fl]

cexp2 [fl]

cexpm1 [fl]

clog10 [fl]

clog1p [fl]

clog2 [fl]

clgamma [fl]

ctgamma [fl]

E [0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ] *

PRI [abcdefghijklmnopqrstuvwxyzX] *

SCN [abcdefghijklmnopqrstuvwxyzX] *

LC_ [ABCDEFGHIJKLMNOPQRSTUVWXYZ] *

SIG [ABCDEFGHIJKLMNOPQRSTUVWXYZ] *

SIG_ [ABCDEFGHIJKLMNOPQRSTUVWXYZ] *

int * _t

uint * _t

INT * _MAX

INT * _MIN

INT * _C

UINT * _MAX

UINT * _MIN

UI NT * _C

str [abcdefghijklmnopqrstuvwxyz] *

mem [abcdefghijklmnopqrstuvwxyz] *

wcs [abcdefghijklmnopqrstuvwxyz] *


-

Simon。



Actually, "str_" is OK. The str prefix is only reserved when followed
by a lowercase letter.

Reserved identifiers include:

is[abcdefghijklmnopqrstuvwxyz]*
to[abcdefghijklmnopqrstuvwxyz]*
cerf
cerfc
cexp2
cexpm1
clog10
clog1p
clog2
clgamma
ctgamma
cerf[fl]
cerfc[fl]
cexp2[fl]
cexpm1[fl]
clog10[fl]
clog1p[fl]
clog2[fl]
clgamma[fl]
ctgamma[fl]
E[0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ]*
PRI[abcdefghijklmnopqrstuvwxyzX]*
SCN[abcdefghijklmnopqrstuvwxyzX]*
LC_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*
SIG[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*
SIG_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*
int*_t
uint*_t
INT*_MAX
INT*_MIN
INT*_C
UINT*_MAX
UINT*_MIN
UINT*_C
str[abcdefghijklmnopqrstuvwxyz]*
mem[abcdefghijklmnopqrstuvwxyz]*
wcs[abcdefghijklmnopqrstuvwxyz]*

--
Simon.


这篇关于备用功能名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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