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 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿