假设我在C#中有这个:
class OverloadTest
{
void Main()
{
CallWithDelegate(SomeOverloadedMethod);
}
delegate void SomeDelegateWithoutParameters();
delegate void SomeDelegateWithParameter(int n);
void CallWithDelegate(SomeDelegateWithoutParameters del) { }
void CallWithDelegate(SomeDelegateWithParameter del) { }
void SomeOverloadedMethod() { }
void SomeOverloadedMethod(int n) { }
}
Run Code Online (Sandbox Code Playgroud)
当然,这不会编译,因为该行CallWithDelegate(SomeOverloadedMethod);是模糊的.
现在,假设只有一个CallWithDelegate(SomeDelegateWithoutParameter del)函数(没有重载).在这种情况下,没有歧义,因为从似乎正在发生的事情,编译器可以查看参数类型并SomeOverloadedMethod(int n)从候选列表中丢弃(因为它只能占用a SomeDelegateWithoutParameters),因此它编译.
我不打算写这样的代码; 从编译器编写者的角度来看,这只是出于好奇.我找不到关于这个问题的答案,因为用语言表达是很困惑的.
我想知道C#中是否有任何方法可以消除Main()给定示例中的调用,以便编译.如何指定它以便它被解析为CallWithDelegate(SomeDelegateWithoutParameters del)传递SomeOverloadedMethod()或被CallWithDelegate(SomeDelegateWithParameter del)传递SomeOverloadedMethod(int n)?
我正在尝试在C中构建一个最小程序来调用Rust函数,最好用#![no_std]Windows 编译,使用GCC 6.1.0和rustc 1.11.0-nightly (bb4a79b08 2016-06-15) x86_64-pc-windows-gnu.这是我先尝试过的:
main.c中
#include <stdio.h>
int sum(int, int);
int main()
{
printf("Sum is %d.\n", sum(2, 3));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
sum.rs
#![no_std]
#![feature(libc)]
extern crate libc;
#[no_mangle]
pub extern "C" fn sum(x: libc::c_int, y: libc::c_int) -> libc::c_int
{
x + y
}
Run Code Online (Sandbox Code Playgroud)
然后我试着跑:
rustc --crate-type=staticlib --emit=obj sum.rs
Run Code Online (Sandbox Code Playgroud)
但得到了:
error: language item required, but not found: `panic_fmt`
error: language item required, but not found: `eh_personality`
error: language item required, but not found: `eh_unwind_resume` …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有 GCC 4.9.3 和 Rust 1.9.0 稳定版的 MinGW 在 Windows 中构建一个调用 Rust 函数的 C 简单应用程序。这是源代码:
测试.rs
#![crate_type = "staticlib"]
#[no_mangle]
pub extern "C" fn get_number() -> isize {
42 as isize
}
Run Code Online (Sandbox Code Playgroud)
主文件
#include <stdio.h>
int get_number();
int main()
{
printf("Hello, world!\n");
printf("Number is %d.\n", get_number());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,我知道我应该在 Rust 等中使用 C 兼容类型。但是在进入程序正确性之前,有一个问题是 Rust 似乎正在生成 GCC 不理解的目标文件。这是我正在尝试的:
rustc --emit obj test.rs
gcc -c main.c
gcc -static-libgcc test.o main.o -lmingw32 -o test.exe
Run Code Online (Sandbox Code Playgroud)
但是链接器命令以:
test.o: file not recognized: File format not …Run Code Online (Sandbox Code Playgroud) 我是Xcode编程的新手,我正在尝试使用OpenGL创建一个iPhone游戏,支持60 FPS的视网膜显示,但运行速度太慢.我基于developer.apple上的GLSprite示例.我已经尽可能地优化了它,但它在模拟器上一直运行<30 FPS(我还没有在真实设备上测试它 - 也许它更快?).瓶颈似乎是绘制多边形 - 我使用了非常小的纹理(256x256 PNG)和像素格式(RGBA4444); 我已禁用混合; 我已将所有转换代码移至加载阶段,希望获得更好的性能; 一切都没有成功.我保持一个顶点数组存储一切为了这一步,然后绘制使用GL_TRIANGLES一个函数调用 - 因为我觉得它比调用多个调用glDrawArrays更快.当我达到大约120个顶点(每个矩形精灵6个)时,它开始滞后,但在许多地方我读过iPhone甚至可以处理数百万个顶点.下面的代码有什么问题?OpenGL是在iPhone上渲染图形的最快方式吗?如果没有,我还应该使用什么?
OpenGL加载代码,在开头只调用一次:
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,texture[0]); //Binds a texture loaded previously with the code given below
glVertexPointer(3, GL_FLOAT, 0, vertexes); //The array holding the vertexes
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, uvCoord); //The array holding the uv coordinates
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Run Code Online (Sandbox Code Playgroud)
纹理加载方法:
- (void)loadSprite:(NSString*)filename intoPos:(int)pos { //Loads a texture within the bundle, at the given position …Run Code Online (Sandbox Code Playgroud)