Aecupy 2018-04-26 09:58 采纳率: 50%
浏览 694
已结题

RPC编程的时候出现的左值问题

i found a releative manual page about l-value on msdn.

you can check it here: https://msdn.microsoft.com/en-us/library/bkbs2cds.aspx

there is an example in this page, but it dose not work as it shows.

msdn上的左值演示,微软的扩展支持,当强制转换一个左值但不会改变变量的长度的时候,转换完依旧是一个左值,msdn上的示例也是想表达这个,但是实际测试的时候并没有其说明的效果,两个赋值表达式都是编译错误。

char *p ;  
short  i;  
long l;  

(long *) p = &l ;       /* Legal cast   */     // this statement can not complie sucess
(long) i = l ;          /* Illegal cast */  

i am not sure what's your result.

here is an example of mime:
然后自己写了一个实例,将char*类型指针转换成int*指针的时候,指针就无法自加了

char* pBuffer = new char[1024];

((int*)pBuffer)++;     //  the result is the same as the previous. it will issue : ++ need l-value

and the /ZA is not including in the complie cmd line.

the main purpose is that, the midl.exe will generate the samiliar code as previous. such as:

类似的midl编译一个idl文件生成的对应c文件中也有类似代码,并不能直接编译通过。不知道是不是哪里没有设置好。

[ RPCSync_s.c ]

    Result = 0;
    RpcTryFinally
        {
        RpcTryExcept
            {
            if ( (_pRpcMessage->DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION )
                NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING) &__MIDL_ProcFormatString.Format[0] );

            Param1 = *(( int __RPC_FAR * )_StubMsg.Buffer)++;   //  issue error: ++ need l-value
            Param2 = *(( int __RPC_FAR * )_StubMsg.Buffer)++;   //  issue error: ++ need l-value

i am waiting for code god to help me here, thk very much!

另外有没有C/C++实现的 RPC 同步调用的示例,能否编译通过

  • 写回答

1条回答 默认 最新

  • 白色一大坨 2018-04-27 03:21
    关注

    查了一下,这个应该是msdn写错了吧,一般来说,这样做是正常的:
    char *p;
    short i;
    long l;

    p = (char*)&l;       /* Legal cast   */
    i = (short)l;          /* Illegal cast */
    
    一般的类型转换,都是在等号右侧来做的,在左侧做,应该是无法通过吧,因为左值要求不能是一个算式,你最后这段代码,我感觉调整一下括号似乎可以,因为主要问题是内部那个自加变量进行了类型转换造成的,比如以下代码:
    long l;
    char* pBuffer = new char[1024];
    strcpy(pBuffer, "11112222");
    l = *(long *)(pBuffer);
    l = *(long *)((pBuffer) += sizeof(long));
    后面两次执行的结果,long分别是0x31313131,0x32323232,这样一个做法应该是可以达到目的的,请看一下,调整一下括号
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?