How to satisfy **_Ctype_struct__GError with a literal?

agolangf · · 838 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am trying this:</p> <pre><code>C.notify_notification_show(n, &amp;new(C.GError)) </code></pre> <p>It complains that I <code>cannot take the address of new(_Ctype_struct__GError)</code>.</p> <p>How should I do it without assigning it in a variable?</p> <hr/>**评论:**<br/><br/>chrj: <pre><p><code>new</code> already returns a pointer. Try just removing the <code>&amp;</code>.</p></pre>dominikh: <pre><p>He needs a pointer to a pointer. At the same time, using any form of <code>new</code> in that function call defeats the point of the second argument, which is basically the equivalent to an <code>error</code> return in Go.</p></pre>chrj: <pre><p>You&#39;re right. I didn&#39;t notice the double pointer. I haven&#39;t had my morning coffee yet :)</p></pre>decapolar: <pre><p>Well I did this and it worked:</p> <pre><code>new(*C.GError) </code></pre></pre>epiris: <pre><p>I don&#39;t know what library you are using but they can not deref the value with that, i.e. <code>**v</code> would panic. I really don&#39;t think you should do this, I would consider any code that did low quality: <code>&amp;[]*int{new(int)}[0]</code></p></pre>mixiegen: <pre><pre><code>var err = new(C.GError) C.notify_notification_show(n, &amp;err) </code></pre> <p>Not any value can be taken address in Go: <a href="https://go101.org/article/summaries.html#not-addressable" rel="nofollow">https://go101.org/article/summaries.html#not-addressable</a></p> <p><code>new</code> is a function, function return results can&#39;t be taken addresses.</p></pre>decapolar: <pre><p>Need a one liner.</p></pre>tv64738: <pre><p>Why?</p></pre>feddasch: <pre><p>Add a semicolon after the variable</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

838 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传