Re: Lambda expressions: Dangerous Madness



Pavel Minaev wrote:

signalling callbacks). So I do this:

list.Sort((x, y) => x - y);

Beware of overflow: this is not a good comparison function. E.g. see:

using System;
class App
{
static void Main()
{
int a = int.MaxValue - 3;
int b = int.MinValue + 3; // so a > b, right?
Console.WriteLine("a = {0}, b = {1}, a > b = {2}", a, b, a > b);
Console.WriteLine(a - b); // so this is positive, right?
// a - b = -7 => oops!
}
}

stream.BeginRead(
buffer,
offset,
count,
delegate(IAsyncResult ar)
{
...
},
null);

This manual continuation-passing style cries out for a machine
translation. I've still got this one on my todo list...

-- Barry

--
http://barrkel.blogspot.com/
.



Relevant Pages

  • [PATCH] epca.c: reformat comments and coding style improvements
    ... static int nbdevs, num_cards, liloconfig; ... This structure is NOT used to overlay the cards physical channel ... static void memwinoff ... static struct channel *verifyChannel ...
    (Linux-Kernel)
  • [PATCH 2/7] dlm: communication
    ... +static struct task_struct *recv_task; ... +static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr) ... +static void lowcomms_data_ready ...
    (Linux-Kernel)
  • [git patches] net driver updates for .27
    ... Add documentation for the driver. ... +static inline int adap2type ... typedef struct board_info { ...
    (Linux-Kernel)
  • [PATCH 3/8] dlm: communication
    ... +static struct task_struct *recv_task; ... +static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr) ... +static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port, ...
    (Linux-Kernel)
  • [2.6 patch] misc drivers/char/ cleanups
    ... +static int __init espserial_init ... +static struct work_struct genrtc_task; ... -i2cmdSetSeq(unsigned char type, unsigned char size, unsigned char *string) ... static void set_params; ...
    (Linux-Kernel)