- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在研究有关 Linux 控制台蛇游戏的 C 源代码(代码在 github 上找到)。
有人可以向我解释一下移动功能吗?
有没有办法将输入键从箭头修改为 wsad
?
如何在游戏开始前给出边界的尺寸?
代码:
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#define SNAKE_ARRAY_SIZE 310
//Linux Libraries
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
//Linux Constants
//Controls (arrow keys for Manjaro)
#define UP_ARROW 'A'
#define LEFT_ARROW 'D'
#define RIGHT_ARROW 'C'
#define DOWN_ARROW 'B'
#define ENTER_KEY 10
const char SNAKE_HEAD = '@';
const char SNAKE_BODY = '*';
const char WALL = '|';
const char CEIL = '-';
const char FOOD = 'X';
const char BLANK = ' ';
//Linux Functions - These functions emulate some functions from the windows only conio header file
void gotoxy(int x,int y)
{
printf("%c[%d;%df",0x1B,y,x);
}
int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
char getch()
{
char c;
system("stty raw");
c= getchar();
system("stty sane");
return(c);
}
void clrscr()
{
system("clear");
return;
}
//End linux Functions
//This should be the same on both operating systems
#define EXIT_BUTTON 27 //ESC
#define PAUSE_BUTTON 112 //P
char waitForAnyKey(void)
{
int pressed;
while(!kbhit());
pressed = getch();
return((char)pressed);
}
int getGameSpeed()
{
int speed = 1;
clrscr();
while(speed < 1 || speed > 9){
return(speed);
}
return 1;
}
//This function checks if a key has pressed, then checks if its any of the arrow keys/ p/esc key. It changes direction acording to the key pressed.
int checkKeysPressed(int direction)
{
int pressed;
if(kbhit()) //If a key has been pressed
{
pressed=getch();
if (direction != pressed)
{
if(pressed == DOWN_ARROW && direction != UP_ARROW)
direction = pressed;
else if (pressed == UP_ARROW && direction != DOWN_ARROW)
direction = pressed;
else if (pressed == LEFT_ARROW && direction != RIGHT_ARROW)
direction = pressed;
else if (pressed == RIGHT_ARROW && direction != LEFT_ARROW)
direction = pressed;
}
}
return(direction);
}
//Cycles around checking if the x y coordinates ='s the snake coordinates as one of this parts
//One thing to note, a snake of length 4 cannot collide with itself, therefore there is no need to call this function when the snakes length is <= 4
int collisionSnake (int x, int y, int snakeXY[][SNAKE_ARRAY_SIZE], int snakeLength, int detect)
{
int i;
for (i = detect; i < snakeLength; i++) //Checks if the snake collided with itself
{
if ( x == snakeXY[0][i] && y == snakeXY[1][i])
return(1);
}
return(0);
}
//Generates food & Makes sure the food doesn't appear on top of the snake <- This sometimes causes a lag issue!!! Not too much of a problem tho
int generateFood(int foodXY[], int width, int height, int snakeXY[][SNAKE_ARRAY_SIZE], int snakeLength)
{
do
{
srand ( time(NULL) );
foodXY[0] = rand() % (width-2) + 2;
srand ( time(NULL) );
foodXY[1] = rand() % (height-6) + 2;
} while (collisionSnake(foodXY[0], foodXY[1], snakeXY, snakeLength, 0)); //This should prevent the "Food" from being created on top of the snake. - However the food has a chance to be created ontop of the snake, in which case the snake should eat it...
gotoxy(foodXY[0] ,foodXY[1]);
printf("%c", FOOD);
return(0);
}
/*
Moves the snake array forward, i.e.
This:
x 1 2 3 4 5 6
y 1 1 1 1 1 1
Becomes This:
x 1 1 2 3 4 5
y 1 1 1 1 1 1
Then depending on the direction (in this case west - left) it becomes:
x 0 1 2 3 4 5
y 1 1 1 1 1 1
snakeXY[0][0]--; <- if direction left, take 1 away from the x coordinate
*/
void moveSnakeArray(int snakeXY[][SNAKE_ARRAY_SIZE], int snakeLength, int direction)
{
int i;
for( i = snakeLength-1; i >= 1; i-- )
{
snakeXY[0][i] = snakeXY[0][i-1];
snakeXY[1][i] = snakeXY[1][i-1];
}
/*
because we don't actually know the new snakes head x y,
we have to check the direction and add or take from it depending on the direction.
*/
switch(direction)
{
case DOWN_ARROW:
snakeXY[1][0]++;
break;
case RIGHT_ARROW:
snakeXY[0][0]++;
break;
case UP_ARROW:
snakeXY[1][0]--;
break;
case LEFT_ARROW:
snakeXY[0][0]--;
break;
}
return;
}
void move(int snakeXY[][SNAKE_ARRAY_SIZE], int snakeLength, int direction)
{
int x;
int y;
//Remove the tail ( HAS TO BE DONE BEFORE THE ARRAY IS MOVED!!!!! )
x = snakeXY[0][snakeLength-1];
y = snakeXY[1][snakeLength-1];
gotoxy(x,y);
printf("%c",BLANK);
//Changes the head of the snake to a body part
gotoxy(snakeXY[0][0],snakeXY[1][0]);
printf("%c", SNAKE_BODY);
moveSnakeArray(snakeXY, snakeLength, direction);
gotoxy(snakeXY[0][0],snakeXY[1][0]);
printf("%c",SNAKE_HEAD);
gotoxy(1,1); //Gets rid of the darn flashing underscore.
return;
}
//This function checks if the snakes head his on top of the food, if it is then it'll generate some more food...
int eatFood(int snakeXY[][SNAKE_ARRAY_SIZE], int foodXY[])
{
if (snakeXY[0][0] == foodXY[0] && snakeXY[1][0] == foodXY[1])
{
foodXY[0] = 0;
foodXY[1] = 0; //This should prevent a nasty bug (loops) need to check if the bug still exists...
printf("\7"); //Beep
return(1);
}
return(0);
}
int collisionDetection(int snakeXY[][SNAKE_ARRAY_SIZE], int consoleWidth, int consoleHeight, int snakeLength ) //Need to Clean this up a bit
{
int colision = 0;
if ((snakeXY[0][0] == 1) || (snakeXY[1][0] == 1) || (snakeXY[0][0] == consoleWidth) || (snakeXY[1][0] == consoleHeight - 4)) //Checks if the snake collided wit the wall or it's self
colision = 1;
else
if (collisionSnake(snakeXY[0][0], snakeXY[1][0], snakeXY, snakeLength, 1)) //If the snake collided with the wall, there's no point in checking if it collided with itself.
colision = 1;
return(colision);
}
void refreshInfoBar(int score, int speed)
{
gotoxy(5,23);
printf("Score: %d", score);
gotoxy(5,24);
printf("Speed: %d", speed);
gotoxy(52,23);
printf("Coders : n/a");
gotoxy(52,24);
printf("Version: 0.1");
return;
}
void gameOverScreen(void)
{
int x = 17, y = 3;
gotoxy(x,y++);
printf(":'######::::::'###::::'##::::'##:'########:\n");
gotoxy(x,y++);
printf("'##... ##::::'## ##::: ###::'###: ##.....::\n");
gotoxy(x,y++);
printf(" ##:::..::::'##:. ##:: ####'####: ##:::::::\n");
gotoxy(x,y++);
printf(" ##::'####:'##:::. ##: ## ### ##: ######:::\n");
gotoxy(x,y++);
printf(" ##::: ##:: #########: ##. #: ##: ##...::::\n");
gotoxy(x,y++);
printf(" ##::: ##:: ##.... ##: ##:.:: ##: ##:::::::\n");
gotoxy(x,y++);
printf(". ######::: ##:::: ##: ##:::: ##: ########:\n");
gotoxy(x,y++);
printf(":......::::..:::::..::..:::::..::........::\n");
gotoxy(x,y++);
printf(":'#######::'##::::'##:'########:'########::'####:\n");
gotoxy(x,y++);
printf("'##.... ##: ##:::: ##: ##.....:: ##.... ##: ####:\n");
gotoxy(x,y++);
printf(" ##:::: ##: ##:::: ##: ##::::::: ##:::: ##: ####:\n");
gotoxy(x,y++);
printf(" ##:::: ##: ##:::: ##: ######::: ########::: ##::\n");
gotoxy(x,y++);
printf(" ##:::: ##:. ##:: ##:: ##...:::: ##.. ##::::..:::\n");
gotoxy(x,y++);
printf(" ##:::: ##::. ## ##::: ##::::::: ##::. ##::'####:\n");
gotoxy(x,y++);
printf(". #######::::. ###:::: ########: ##:::. ##: ####:\n");
gotoxy(x,y++);
printf(":.......::::::...:::::........::..:::::..::....::\n");
waitForAnyKey();
clrscr(); //clear the console
return;
}
//Messy, need to clean this function up
void startGame( int snakeXY[][SNAKE_ARRAY_SIZE], int foodXY[], int consoleWidth, int consoleHeight, int snakeLength, int direction, int score, int speed)
{
int gameOver = 0;
clock_t endWait;
//CLOCKS_PER_SEC-(n-1)*(CLOCKS_PER_SEC/10)
int waitMili = CLOCKS_PER_SEC-(speed)*(CLOCKS_PER_SEC/10); //Sets the correct wait time according to the selected speed
int tempScore = 10*speed;
int oldDirection;
int canChangeDirection = 1;
//int seconds = 1;
endWait = clock() + waitMili;
do
{
if(canChangeDirection)
{
oldDirection = direction;
direction = checkKeysPressed(direction);
}
if(oldDirection != direction)//Temp fix to prevent the snake from colliding with itself
canChangeDirection = 0;
if(clock() >= endWait) //it moves according to how fast the computer running it is...
{
move(snakeXY, snakeLength, direction);
canChangeDirection = 1;
if(eatFood(snakeXY, foodXY))
{
generateFood( foodXY, consoleWidth, consoleHeight, snakeXY, snakeLength); //Generate More Food
snakeLength++;
score+=10;
if( score >= 10*speed+tempScore)
{
speed++;
tempScore = score;
if(speed <= 9)//this needs to be fixed
waitMili = waitMili - (CLOCKS_PER_SEC/10);
else
{
if(waitMili >= 40) //Maximum Speed (the game has to be beatable)
waitMili = waitMili - (CLOCKS_PER_SEC/200);
}
}
refreshInfoBar(score, speed);
}
endWait = clock() + waitMili; //TEMP FIX, NEED TO FIND A WAY TO RESET CLOCK().. Na, seems to work fine this way...
}
gameOver = collisionDetection(snakeXY, consoleWidth, consoleHeight, snakeLength);
if(snakeLength >= SNAKE_ARRAY_SIZE-5) //Just to make sure it doesn't get longer then the array size & crash
{
gameOver = 2;//You Win! <- doesn't seem to work - NEED TO FIX/TEST THIS
score+=1500; //When you win you get an extra 1500 points!!!
}
} while (!gameOver);
switch(gameOver)
{
case 1:
printf("\7"); //Beep
printf("\7"); //Beep
gameOverScreen();
break;
}
return;
}
void loadEnviroment(int consoleWidth, int consoleHeight)//This can be done in a better way... FIX ME!!!! Also i think it doesn't work properly in ubuntu <- Fixed
{
//int i;
int x = 1, y = 1;
int rectangleHeight = consoleHeight - 4;
clrscr(); //clear the console
gotoxy(x,y); //Top left corner
for (; y < rectangleHeight; y++)
{
gotoxy(x, y); //Left Wall
printf("%c",WALL);
gotoxy(consoleWidth, y); //Right Wall
printf("%c",WALL);
}
y = 1;
for (; x < consoleWidth+1; x++)
{
gotoxy(x, y); //Left Wall
printf("%c",WALL);
gotoxy(x, rectangleHeight); //Right Wall
printf("%c",WALL);
}
return;
}
void loadSnake(int snakeXY[][SNAKE_ARRAY_SIZE], int snakeLength)
{
int i;
/*
First off, The snake doesn't actually have enough XY coordinates (only 1 - the starting location), thus we use
these XY coordinates to "create" the other coordinates. For this we can actually use the function used to move the snake.
This helps create a "whole" snake instead of one "dot", when someone starts a game.
*/
//moveSnakeArray(snakeXY, snakeLength); //One thing to note ATM, the snake starts of one coordinate to whatever direction it's pointing...
//This should print out a snake :P
for (i = 0; i < snakeLength; i++)
{
gotoxy(snakeXY[0][i], snakeXY[1][i]);
printf("%c", SNAKE_BODY); //Meh, at some point I should make it so the snake starts off with a head...
}
return;
}
void prepairSnakeArray(int snakeXY[][SNAKE_ARRAY_SIZE], int snakeLength)
{
int i;
int snakeX = snakeXY[0][0];
int snakeY = snakeXY[1][0];
for(i = 1; i <= snakeLength; i++)
{
snakeXY[0][i] = snakeX + i;
snakeXY[1][i] = snakeY;
}
return;
}
//This function loads the environment, snake, etc
void loadGame(void)
{
int snakeXY[2][SNAKE_ARRAY_SIZE]; //Two Dimensional Array, the first array is for the X coordinates and the second array for the Y coordinates
int snakeLength = 2; //Starting Length
int direction = LEFT_ARROW; //DO NOT CHANGE THIS TO RIGHT ARROW, THE GAME WILL INSTANTLY BE OVER IF YOU DO!!! <- Unless the prepareSnakeArray function is changed to take into account the direction....
int foodXY[] = {5,5};// Stores the location of the food
int score = 0;
//int level = 1;
//Window Width * Height - at some point find a way to get the actual dimensions of the console... <- Also somethings that display don't take this dimensions into account.. need to fix this...
int consoleWidth = 80;
int consoleHeight = 25;
int speed = getGameSpeed();
//The starting location of the snake
snakeXY[0][0] = 40;
snakeXY[1][0] = 10;
loadEnviroment(consoleWidth, consoleHeight); //borders
prepairSnakeArray(snakeXY, snakeLength);
loadSnake(snakeXY, snakeLength);
generateFood( foodXY, consoleWidth, consoleHeight, snakeXY, snakeLength);
refreshInfoBar(score, speed); //Bottom info bar. Score, Level etc
startGame(snakeXY, foodXY, consoleWidth, consoleHeight, snakeLength, direction, score, speed);
return;
}
int main() //Need to fix this up
{
loadGame();
return(0);
}
最佳答案
move()
函数做了 3 件事:
以下是来自编译器的消息:
gcc -ggdb -Wall -Wextra -Wconversion -pedantic -std=gnu11 -c "untitled.c" (in directory: /home/richard/Documents/forum)
untitled.c: In function ‘gotoxy’:
untitled.c:32:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
printf("%c[%d;%df",0x1B,y,x);
^~~~~~
untitled.c:32:9: warning: incompatible implicit declaration of built-in function ‘printf’
untitled.c:32:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘kbhit’:
untitled.c:44:20: warning: negative integer implicitly converted to unsigned type [-Wsign-conversion]
newt.c_lflag &= ~(ICANON | ECHO);
^~
untitled.c:49:12: warning: implicit declaration of function ‘getchar’; did you mean ‘getcwd’? [-Wimplicit-function-declaration]
ch = getchar();
^~~~~~~
getcwd
untitled.c:54:16: error: ‘EOF’ undeclared (first use in this function); did you mean ‘VEOF’?
if(ch != EOF)
^~~
VEOF
untitled.c:54:16: note: each undeclared identifier is reported only once for each function it appears in
untitled.c:56:9: warning: implicit declaration of function ‘ungetc’ [-Wimplicit-function-declaration]
ungetc(ch, stdin);
^~~~~~
untitled.c:56:20: error: ‘stdin’ undeclared (first use in this function); did you mean ‘sin’?
ungetc(ch, stdin);
^~~~~
sin
untitled.c: In function ‘getch’:
untitled.c:67:12: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]
c= getchar();
^~~~~~~
untitled.c: In function ‘generateFood’:
untitled.c:149:17: warning: conversion to ‘unsigned int’ from ‘time_t {aka long int}’ may alter its value [-Wconversion]
srand ( time(NULL) );
^~~~
untitled.c:151:17: warning: conversion to ‘unsigned int’ from ‘time_t {aka long int}’ may alter its value [-Wconversion]
srand ( time(NULL) );
^~~~
untitled.c:156:5: warning: incompatible implicit declaration of built-in function ‘printf’
printf("%c", FOOD);
^~~~~~
untitled.c:156:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘move’:
untitled.c:219:5: warning: incompatible implicit declaration of built-in function ‘printf’
printf("%c",BLANK);
^~~~~~
untitled.c:219:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘eatFood’:
untitled.c:243:9: warning: incompatible implicit declaration of built-in function ‘printf’
printf("\7"); //Beep
^~~~~~
untitled.c:243:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘refreshInfoBar’:
untitled.c:265:5: warning: incompatible implicit declaration of built-in function ‘printf’
printf("Score: %d", score);
^~~~~~
untitled.c:265:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘gameOverScreen’:
untitled.c:285:5: warning: incompatible implicit declaration of built-in function ‘printf’
printf(":'######::::::'###::::'##::::'##:'########:\n");
^~~~~~
untitled.c:285:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘startGame’:
untitled.c:329:20: warning: conversion to ‘int’ from ‘long int’ may alter its value [-Wconversion]
int waitMili = CLOCKS_PER_SEC-(speed)*(CLOCKS_PER_SEC/10); //Sets the correct wait time according to the selected speed
^~~~~~~~~~~~~~
untitled.c:367:36: warning: conversion to ‘int’ from ‘long int’ may alter its value [-Wconversion]
waitMili = waitMili - (CLOCKS_PER_SEC/10);
^~~~~~~~
untitled.c:371:40: warning: conversion to ‘int’ from ‘long int’ may alter its value [-Wconversion]
waitMili = waitMili - (CLOCKS_PER_SEC/200);
^~~~~~~~
untitled.c:396:13: warning: incompatible implicit declaration of built-in function ‘printf’
printf("\7"); //Beep
^~~~~~
untitled.c:396:13: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘loadEnviroment’:
untitled.c:419:9: warning: incompatible implicit declaration of built-in function ‘printf’
printf("%c",WALL);
^~~~~~
untitled.c:419:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c:429:9: warning: incompatible implicit declaration of built-in function ‘printf’
printf("%c",WALL);
^~~~~~
untitled.c:429:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: In function ‘loadSnake’:
untitled.c:453:9: warning: incompatible implicit declaration of built-in function ‘printf’
printf("%c", SNAKE_BODY); //Meh, at some point I should make it so the snake starts off with a head...
^~~~~~
untitled.c:453:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
untitled.c: At top level:
untitled.c:517:2: error: stray ‘`’ in program
}```
^
untitled.c:517:3: error: stray ‘`’ in program
}```
^
untitled.c:517:4: error: stray ‘`’ in program
}```
^
Compilation failed.
关于c - Linux下贪吃蛇游戏源代码(C语言),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58466603/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!