关于编译器和内存理论的C题

问题描述 投票:0回答:1

在不调用任何“call”或“jump”函数的情况下,我们需要按照“这是第一个”然后“这是第二个”的顺序获得输出。在我看来,我们需要将“粗体”与内存和指令一起使用。我们也不能称之为“学习”的功能。

#include <stdio.h>

void study()
{
    printf("this is the second.\n");
}

void study2()
{
    int bold[4];
    // can only modify this section BEGIN
    // cant call study(), maybe use study(pointer to function)


    // can only modify this section END
    printf("this is the first\n");
}

int main(int argc, char *argv[])
{
    study2();
    return 0;
}
c memory compiler-construction buffer-overflow instructions
1个回答
0
投票

也许不是OP的初衷,但宏可以解决问题。

#include <stdio.h>

void study() {
  printf("this is the second.\n");
}

void study2() {
  int bold[4];
  // can only modify this section BEGIN
  // Without calling any "call" or "jump" function, 
  #define F1 study
  #define F2 study2
  #define study2() F2(); F1();
  // can only modify this section END
  printf("this is the first\n");
}

int main(int argc, char *argv[]) {
  study2();
  return 0;
}

输出

this is the first
this is the second.

当 - 可能违反

© www.soinside.com 2019 - 2024. All rights reserved.