我正在使用C ++,因为它的目标语言现在编程语言。我打一个非常奇怪的回溯。

#1  0x08048d09 in factorial (n=0x8052160) at ir.cpp:35
35      shore::builtin__int * __return = NULL;
(gdb) bt
#0  shore::builtin__int::__mul__ (this=0x8052160, other=0x8052288) at /home/alex/projects/shore/shore/runtime/int.h:36
#1  0x08048d09 in factorial (n=0x8052160) at ir.cpp:35
#2  0x08048cfa in factorial (n=0x80520b8) at ir.cpp:35
#3  0x08048cfa in factorial (n=0x8052018) at ir.cpp:35
#4  0x08048d6f in main () at ir.cpp:43

具体而言,似乎声明的的返回类型以某种方式触发__mul 以被称为上builtin__int方法,我不知道为什么。 builtin__int如下:

#ifndef _SHORE_INT_H
#define _SHORE_INT_H

#include "gc.h"


namespace shore {
    class builtin__int : public shore::Object {
        public:
            // Some day this will be arbitrary percision, but not today.
            long long value;

            static builtin__int* new_instance(long long value_) {
                builtin__int* val = new builtin__int(value_);
                shore::GC::register_object(val);
                return val;
            }

            builtin__int(long long value_) {
                this->value = value_;
            }

            builtin__bool* __eq__(builtin__int* other) {
                return builtin__bool::new_instance(this->value == other->value);
            }

            builtin__int* __add__(builtin__int* other) {
                return builtin__int::new_instance(this->value + other->value);
            }

            builtin__int* __sub__(builtin__int* other) {
                return builtin__int::new_instance(this->value - other->value);
            }

            builtin__int* __mul__(builtin__int* other) {
                return builtin__int::new_instance(this->value * other->value);
            }
    };
}
#endif

任何想法,在地球上什么是引人注目的C ++调用的 MUL 方式?

编辑:添加ir.cpp的源

#include "builtins.h"
#include "frame.h"
#include "object.h"
#include "state.h"
std::vector < shore::Frame * >shore::State::frames;
shore::GCSet shore::GC::allocated_objects;
class
    factorial__frame:
    public
    shore::Frame {
  public:
    shore::builtin__int *
    n;
    shore::GCSet
    __get_sub_objects() {
    shore::GCSet s;
    s.
    insert(this->n);
    return
        s;
}};
class
    main__frame:
    public
    shore::Frame {
  public:
    shore::GCSet
    __get_sub_objects() {
    shore::GCSet s;
    return
        s;
}};
shore::builtin__int * factorial(shore::builtin__int * n)
{
    shore::builtin__int * __return = NULL;
    factorial__frame frame;
    shore::State::frames.push_back(&frame);
    frame.n = NULL;
    frame.n = n;
    if (((frame.n)->__eq__(shore::builtin__int::new_instance(0)))->value) {
    __return = shore::builtin__int::new_instance(1);
    shore::GC::collect();
    shore::State::frames.pop_back();
    return __return;
    }
    __return =
    (frame.n)->
    __mul__(factorial
        ((frame.n)->
         __sub__(shore::builtin__int::new_instance(1))));
    shore::GC::collect();
    shore::State::frames.pop_back();
    return __return;
}
int
main()
{
    main__frame     frame;
    shore::State::frames.push_back(&frame);
    builtin__print(factorial(shore::builtin__int::new_instance(3)));
    shore::State::frames.pop_back();
}
有帮助吗?

解决方案

猜测的一点:在该行shore::builtin__int * __return = NULL;初始化什么也不做,因为它总是覆盖。编译器将完全有权(一)重新排序下来到__return分配,由确实呼叫__mul__然后(B)完全删除代码的声明。但也许它留在调试信息源行了,要不就是连接或GDB已经结束了思维的调用指令属于附近的多个源线的错误之一。

从不信任源代码调试,除非你可以看到拆卸了。编译语言 - 呸,骗子。等等。

其他提示

用双下划线标识符名称被保留。你可以用编译器生成的名称被碰撞。

在我看来像翻译失败,并以某种方式GCC(或其他)是认为岸上:: builtin__int是某种类型的值,而你试图通过__return乘它,而不是声明价值__return作为型岸:: builtin__int * ...

显然,如果这件事情被编译可言的,给你运行时错误,那么任何类型的乘法会给你是一个有效的LHS ...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top