小编Dar*_*ell的帖子

如何字节换一个双?

我正在尝试为在Win XP上运行的C++程序编写一个byteswap例程.我正在使用Visual Studio 2008编译.这就是我想出的:

int byteswap(int v) // This is good
{
    return _byteswap_ulong(v);
}

double byteswap(double v) // This doesn't work for some values
{
    union { // This trick is first used in Quake2 source I believe :D
        __int64 i;
        double  d;
    } conv;
    conv.d = v;
    conv.i = _byteswap_uint64(conv.i);
    return conv.d;
}
Run Code Online (Sandbox Code Playgroud)

还有一个测试功能:

void testit() {
    double  a, b, c;
    CString str;

    for (a = -100; a < 100; a += 0.01) {
        b = byteswap(a);
        c …
Run Code Online (Sandbox Code Playgroud)

c++ endianness visual-studio-2008

6
推荐指数
3
解决办法
9873
查看次数

将上一个错误传递给自定义错误重定向的最佳方法?

想知道你对这个解决方案的看法,如果这是将错误信息传递给自定义页面的正确方法吗?

在web.config中:

    <customErrors mode="On" defaultRedirect="~/Error.aspx"></customErrors>
Run Code Online (Sandbox Code Playgroud)

在Global.asax中:

<script RunAt="server">
    void Application_Error(object sender, EventArgs e)
    {
    Exception ex = Server.GetLastError();
    if (ex != null && Session != null)
    {
        ex.Data.Add("ErrorTime", DateTime.Now);
        ex.Data.Add("ErrorSession", Session.SessionID);
        HttpContext.Current.Cache["LastError"] = ex;
    }
    }

</script>
Run Code Online (Sandbox Code Playgroud)

在我的Error.aspx.cs中:

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack) return;

    if (HttpContext.Current.Cache["LastError"] != null)
    {
        Exception ex = (Exception)HttpContext.Current.Cache["LastError"];
        if (ex.Data["ErrorTime"] != null && ex.Data["ErrorSession"] != null)
            if ((DateTime)ex.Data["ErrorTime"] > DateTime.Now.AddSeconds(-30d) && ex.Data["ErrorSession"].ToString() == Session.SessionID)
                Label1.Text = ex.InnerException.Message;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题:我不想从Global.asax做一个Server.Transfer因为..我不知道.对我来说似乎很笨拙.希望能够将customErrors更改为RemoteOnly.所以必须在某处保存最后一个异常,但不能是Session,所以保存到Cache但是有一些额外的数据(时间和SessionID),因为Cache是​​全局的,并且希望确保不向某人显示错误的错误.


我有点改变了我的代码.现在它只是: …

asp.net caching custom-errors getlasterror

5
推荐指数
1
解决办法
7665
查看次数