Skip to content

関数の返り値がptr型の場合、f()+1が正常に計算されない #2

@osorosia

Description

@osorosia

現状、関数は自身の型(int/ptr)を保持していないため、f() + 1の箇所で正常に計算されない。

int *f() {
    int *p;
    alloc4(&p, 1, 2, 4, 8);
    return p;
}

int main() {
    return *(f() + 1);
}

理由

  • <ptr> + <int><int> + <int>で区別している
  • <ptr> + 1<ptr>アドレスを(現状では)1 Byte文ずらすため、内部では<ptr> + 8とする必要がある
  • 関数の場合、自身の型を保持していないため、うまくいかない(変数は問題なし)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions