!!" in C code?

I bumped into this strange macro code in /usr/include/linux/kernel.h: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression can be used e.g. in a structure initializer (or where-ever else comma expressions aren't permitted). */ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_NULL(e)

!!“在C代码?

我在/usr/include/linux/kernel.h中遇到了这个奇怪的宏代码: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression can be used e.g. in a structure initializer (or where-ever else comma expressions aren't permitted). */ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_NULL(e) ((void *)si

What the operator `<

<-- is not an operator, it is < and -- written without space. Just to make it clear, I rewrite the code like this- while(0 < --i) First the value of i is decreased, and then compared if it is greater than 0 . Similar question was asked here.

什么运营商`<

<--不是操作员,它是<和--写入没有空间。 为了说清楚,我重写了这样的代码 - while(0 < --i) 首先减少i的值,然后比较它是否大于0 。 这里提出了类似的问题。

>" mean in C?

This question already has an answer here: What is the “-->” operator in C++? 21 answers x --> 0将被读取(x--) > 0 。 x-->0被解析为(x--) > 0 。

>“是否意味着在C?

这个问题在这里已经有了答案: 什么是C ++中的“ - >”运算符? 21个答案 x --> 0将被读取(x--) > 0 。 x-->0被解析为(x--) > 0 。

Why isn't there a "<

This question already has an answer here: What is the “-->” operator in C++? 21 answers --> is not one operator, it is two; (post) decrement and less than. C is whitespace agnostic for the most part, so: x --> y /* is the same as */ x-- > y <-- is the same idea: x <-- y /* is the same as */ x < --y Perhaps you are confusing -> with --> . -> dereferences a

为什么没有“<”

这个问题在这里已经有了答案: 什么是C ++中的“ - >”运算符? 21个答案 -->不是一个操作员,它是两个; (后)递减并小于。 C大部分是空白不可知的,所以: x --> y /* is the same as */ x-- > y <--是一样的想法: x <-- y /* is the same as */ x < --y 也许你很困惑->与--> 。 ->取消引用一个指向它的引用类型的成员的指针。 typedef struct { int x; } foo; int main(void)

How to Sort a List<T> by a property in the object

I have a class called Order which has properties such as OrderId , OrderDate , Quantity , and Total . I have a list of this Order class: List<Order> objListOrder = new List<Order>(); GetOrderList(objListOrder); // fill list of orders Now I want to sort the list based on one property of the Order object, for example I need to sort it by the order date or order id. How can i do thi

如何按对象中的属性对List <T>进行排序

我有一个名为Order的类,它具有OrderId , OrderDate , Quantity和Total等属性。 我有这个Order类的列表: List<Order> objListOrder = new List<Order>(); GetOrderList(objListOrder); // fill list of orders 现在我想根据Order对象的一个​​属性对列表进行排序,例如我需要按订单日期或订单ID对其进行排序。 我如何在C#中执行此操作? 我能想到的最简单的方法是使用Linq: List<Order> SortedList =

Fastest sort of fixed length 6 int array

Answering to another Stack Overflow question (this one) I stumbled upon an interesting sub-problem. What is the fastest way to sort an array of 6 ints? As the question is very low level: we can't assume libraries are available (and the call itself has its cost), only plain C to avoid emptying instruction pipeline (that has a very high cost) we should probably minimize branches, jumps,

最快的固定长度6 int数组

回答另一个堆栈溢出问题(这一个)我偶然发现了一个有趣的子问题。 对6个整数的数组进行排序的最快方法是什么? 由于问题非常低: 我们不能假定图书馆可用(并且通话本身有其成本),只有普通的C 为避免清空指令流水线(成本非常高),我们应该尽量减少分支,跳转以及其他任何类型的控制流程中断(例如隐藏在&&或||序列点后面的流程)。 空间有限,尽量减少寄存器和内存的使用是一个问题,理想情况下,排序可能

Custom Data Annotations IsValid is never invoked. (ASP.NET MVC 2 .NET 4)

I have a custom Data Validation Attribute I've created to make sure the passwords a user inputs are the same, but IsValid is never invoked. Custom attribute: public class IsSameAsAttribute : ValidationAttribute { public String TargetProperty { get; set; } private readonly object _typeId = new object(); public IsSameAsAttribute(string targetProperty) { TargetPropert

自定义数据注释IsValid从不调用。 (ASP.NET MVC 2 .NET 4)

我已经创建了一个自定义的数据验证属性,以确保用户输入的密码相同,但从不调用IsValid。 自定义属性: public class IsSameAsAttribute : ValidationAttribute { public String TargetProperty { get; set; } private readonly object _typeId = new object(); public IsSameAsAttribute(string targetProperty) { TargetProperty = targetProperty; } public override bool IsValid(objec

Adverserial search troubles

I'm writing a Connect4 game with an AI opponent using adversarial search techniques and I have somewhat run into a wall. I feel that I'm not far from a solution but that there's perhaps a problem where I'm switching perspectives (as in: the perspective of which participant I'm basing my evaluation scores on), missing a minus sign somewhere or something like that. The proble

对手寻找麻烦

我正在使用敌对搜索技术与AI对手写一篇Connect4游戏,而且我已经有点碰壁了。 我觉得我离解决方案并不遥远,但是也许存在一个问题,那就是我在切换观点(例如:参与者的角度是基于我的评估分数),在某处丢失了一个负号或类似的东西那。 问题是,在我尝试过的AI中,当玩家有三连胜时,AI选择不阻止玩家,否则AI会玩完美的游戏,或者他更喜欢阻止玩家,即使他有机会赢得比赛。 这似乎也很重要,搜索深度是否是偶数或不均匀的

Proper use of the IDisposable interface

I know from reading the MSDN documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources. To me, "unmanaged" means things like database connections, sockets, window handles, etc. But, I've seen code where the Dispose() method is implemented to free managed resources, which seems redundant to me, since the garbage collector should

正确使用IDisposable接口

通过阅读MSDN文档,我知道IDisposable接口的“主要”用途是清理非托管资源。 对我而言,“非托管”意味着像数据库连接,套接字,窗口句柄等。但是,我已经看到代码中实现了Dispose()方法来释放托管资源,这对我来说似乎是多余的,因为垃圾收集器应该照顾你的。 例如: public class MyCollection : IDisposable { private List<String> _theList = new List<String>(); private Dictionary<String, Point

What does the [Flags] Enum Attribute mean in C#?

From time to time I see an enum like the following: [Flags] public enum Options { None = 0, Option1 = 1, Option2 = 2, Option3 = 4, Option4 = 8 } I don't understand what exactly the [Flags] -attribute does. Anyone have a good explanation or example they could post? The flags attribute should be used whenever the enumerable represents a collection of flags, rather

在C#中,[Flags]枚举属性意味着什么?

我不时会看到如下的枚举: [Flags] public enum Options { None = 0, Option1 = 1, Option2 = 2, Option3 = 4, Option4 = 8 } 我不明白[Flags]属性的作用。 任何人都可以发布一个很好的解释或示例? 只要enumerable表示一组标志而不是一个单独的值,就应该使用flags属性。 这些集合通常使用按位运算符来操作,例如: myProperties.AllowedColors = MyColor.Red | MyColor.Green | MyColor.Blue;