When compiling the code below with the Java compiler from OpenJDK 8, the call to foo() is done via an invokespecial, but when OpenJDK 11 is used, an invokevirtual is emitted.
public class Invoke {
public void call() {
foo();
}
private void foo() {}
}
Run Code Online (Sandbox Code Playgroud)
Output of javap -v -p when javac 1.8.0_282 is used:
public void call();
descriptor: ()V
flags: (0x0001) ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #2 // Method foo:()V
4: return
Run Code Online (Sandbox Code Playgroud)
Output …
我有一个c ++项目,我想转换为Web应用程序.为此,我想使用Emscripten来构建项目.
该项目使用一些外部库.我设法编译或找到大多数库的JavaScript版本,现在我陷入了Boost的困境.实际上我甚至不知道如何启动Boost:他们使用boostrap脚本生成文件来构建库.可以将工具集传递给此脚本,但显然不支持Emscripten.
我的项目使用Boost的以下部分:Thread,Regex,FileSystem,Signals,System.如何使用Emscripten编译这些库?
编辑
按照npclaudiu的回答,我用gcc工具包引导了库,然后编辑project-config.jam配置编译器,替换:
# Compiler configuration. This definition will be used unless
# you already have defined some toolsets in your user-config.jam
# file.
if ! gcc in [ feature.values <toolset> ]
{
using gcc ;
}
Run Code Online (Sandbox Code Playgroud)
同
# Compiler configuration. This definition will be used unless
# you already have defined some toolsets in your user-config.jam
# file.
if ! gcc in [ feature.values <toolset> ]
{
using gcc : : "/full/path/to/em++" ;
} …Run Code Online (Sandbox Code Playgroud) 另一个问题讨论优化器删除对以下调用的合法性new:是否允许编译器优化堆内存分配?。我已阅读问题、答案和N3664。
根据我的理解,编译器可以在“as-if”规则下删除或合并动态分配,即,相对于标准中定义的抽象机,结果程序的行为就像没有进行任何更改一样。
我测试了使用 clang++ 和 g++ 编译以下两个文件程序以及-O1优化,但我不明白如何允许删除分配。
// main.cpp
#include <cstdio>
extern int g_alloc;
static int* foo(int n)
{
// operator new is globally overridden in the other file.
return new int(n);
}
int main(int argc, char** argv)
{
foo(argc);
foo(argc*2);
printf("allocated: %d\n", g_alloc);
return g_alloc;
}
Run Code Online (Sandbox Code Playgroud)
// new.cpp
#include <cstdio>
#include <cstdlib>
#include <new>
int g_alloc = 0;
void* operator new(size_t n)
{
g_alloc += n;
printf("new %lu\n", n);
return malloc(n); …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何强制子相同的虚函数首先调用其父虚函数
我有一个类层次结构,其中每个派生类重写给定的虚函数,并通过调用其父类中的一个来启动它的实现.目标是让每个派生的实现都被执行,但我不喜欢我这样做的方式.
例如,我有这个类:
class base
{
public:
void do_stuff() { do_something(); }
virtual void do_something() { }
};
Run Code Online (Sandbox Code Playgroud)
然后我在几个级别上派生这个类:
class derived_10:
public derived_9 // which inherit from derived_8 and so on until derived_0
// which inherit from base
{
public:
virtual void do_something()
{
// this will also call derived_8::do_something() and so on
// until base::do_something()
derived_9::do_something();
// then, some stuff
}
};
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种解决方案,以确保在调用base :: do_stuff()时将按顺序调用所有derived_x :: do_something(),而不必期望派生类本身执行此操作.您是否了解获得此行为的最佳方法?
我正在向SDL2和Android平台移植一个使用SDL 1.2的C++游戏.到目前为止一切顺利,除了一件事:当我尝试访问SDL_Window的字段时,编译器告诉我
error: invalid use of incomplete type 'SDL_Window {aka struct SDL_Window}'
Run Code Online (Sandbox Code Playgroud)
我认为我的SDL安装可能有问题.我使用以下命令从libsdl.org上的源代码编译了SDL 2.0.0:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_PLATFORM=android-18
Run Code Online (Sandbox Code Playgroud)
然后,我已经将新建的内容和目录中的文件复制libSDL2.so到了.这些文件被提供给CMake并由游戏代码引用.我设法转换每个SDL调用,现在我遇到了这个SDL_Window问题.$ANDROID_TOOLCHAIN/sysroot/usr/libinclude/$ANDROID_TOOLCHAIN/sysroot/usr/include/SDL
我的确在SDL的源代码快速搜索和发现,SDL.h包括SDL_video.h其中包含的类型定义SDL_Window上struct SDL_Window.然后我搜索了这个结构,并且在原始源存档中找不到任何名称的文件src/video/SDL_sysvideo.h.由于它不是API的文件,我怀疑我必须将它包含在我的代码中.
那么,如何在Android中找到SDL2中SDL_Window的定义(如果这是相关的)?