C库命名约定 [英] C library naming conventions

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

问题描述

您好乡亲,我最近才知道在C程序! (这对我来说是巨大的一步,因为C ++是第一语言,我有过接触吓死我了近10年。),从主要面向对象背景的(Java + C#),这是一个非常好的转变。

Hello folks, I recently learned to program in C! (This was a huge step for me, since C++ was the first language, I had contact with and scared me off for nearly 10 years.) Coming from a mostly OO background (Java + C#), this was a very nice paradigm shift.

我爱C.它是这样一个美丽的语言。什么最让我吃惊,是模块化和code重用C的高品位的支持 - 当然,它并不如在面向对象的语言,但仍远远超出了我的期望,命令式语言

I love C. It's such a beautiful language. What surprised me the most, is the high grade of modularity and code reusability C supports - of course it's not as high as in a OO-language, but still far beyond my expectations for an imperative language.

我如何prevent命名客户端code和我的C库code之间的冲突?在Java中有包,在C#中有命名空间。想象一下,我写了一个C库,它提供了操作的添加。这是非常有可能的,客户端已经使用名为​​那样的操作 - ?我该怎么办

How do I prevent naming conflicts between the client code and my C library code? In Java there are packages, in C# there are namespaces. Imagine I write a C library, which offers the operation "add". It is very likely, that the client already uses an operation called like that - what do I do?

我特别想找一个客户友好型解决方案。举例来说,我不希望preFIX我所有的API操作,如myuniquelibname_add的说法。什么是在C世界这个共同的解决办法?你把一个结构的所有API操作,使客户可以选择自己的preFIX?

I'm especially looking for a client friendly solution. For example, I wouldn't like to prefix all my api operations like "myuniquelibname_add" at all. What are the common solutions to this in the C world? Do you put all api operations in a struct, so the client can choose its own prefix?

我很期待我的见解,通过你的答案搞定!

I'm very looking forward to the insights I get through your answers!

尊敬的答复者,谢谢您的解答!我现在看到,prefixes是安全避免命名冲突的唯一途径。所以,我想modifiy我的问题:什么可能性我有,让客户选择自己的preFIX

Dear Answerers, thank You for Your answers! I now see, that prefixes are the only way to safely avoid naming conflicts. So, I would like to modifiy my question: What possibilities do I have, to let the client choose his own prefix?

开卷发布的答案,是一种方法。它没有通常意义上的使用prefixes,但是你preFIX的API - >每个API调用。什么进一步的解决方案是在那里(就像使用例如的#define)?

The answer Unwind posted, is one way. It doesn't use prefixes in the normal sense, but one has to prefix every api call by "api->". What further solutions are there (like using a #define for example)?

这一切都归结为以下两种方法之一:

It all boils down to one of two approaches:


  • 使用结构

  • 使用#define(注:有很多方法,可以如何使用的#define实现的,我的愿望)

我不会接受任何答案,因为我觉得没有正确的答案。一个人选择,而该解决方案取决于具体情况和自己preferences。我,由我自己,会尝试一下你刚才提到,找出最适合我在什么情况下所有的方法。随意张贴论据支持或反对相应答案的意见一定appraoches。

I will not accept any answer, because I think that there is no correct answer. The solution one chooses rather depends on the particular case and one's own preferences. I, by myself, will try out all the approaches You mentioned to find out which suits me best in which situation. Feel free to post arguments for or against certain appraoches in the comments of the corresponding answers.

最后,我想特别感谢:

  • Unwind - for his sophisticated answer including a full implementation of the "struct-method"
  • Christoph - for his good answer and pointing me to Namespaces in C
  • All others - for Your great input

如果有人发现了它适当关闭这个问题(由于没有进一步的见解,期望),他/她应该感到自由地这样做 - 我不能决定这一点,因为我没有C大师

If someone finds it appropriate to close this question (as no further insights to expect), he/she should feel free to do so - I can not decide this, as I'm no C guru.

推荐答案

我没有C大师,但我已经使用了库,这是很常见的使用preFIX到独立的功能。

I'm no C guru, but from the libraries I have used, it is quite common to use a prefix to separate functions.

例如,SDL将使用SDL,OpenGL的将使用GL,等等...

For example, SDL will use SDL, OpenGL will use gl, etc...

这篇关于C库命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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