我正在使用一个使用DirectX的C项目,但我遇到了一个问题.某些DX调用需要一个IID对象,通常用__uuidof.这需要做的一件事是创建一个RenderTargetView.DirectX示例/教程执行此操作:
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
Run Code Online (Sandbox Code Playgroud)
当我尝试调用__uuidof我的C代码时,我收到编译器错误:Error 19 error C4233: nonstandard extension used : '__uuidof' keyword only supported in C++, not C.DirectX有一个C接口,所以我想必须有办法做到这一点,但我不知道它会是什么.谁知道?
我在C中有这个代码,它接受了一堆chars
#include<stdio.h>
# define NEWLINE '\n'
int main()
{
char c;
char str[6];
int i = 0;
while( ((c = getchar()) != NEWLINE))
{
str[i] = c;
++i;
printf("%d\n", i);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输入是:testtesttest
输出:1 2 3 4 5 6 7 8 117 118 119 120
我的问题是:
虽然我明显超出了阵列的容量,为什么我不会出现超出界限(分段错误)的异常?
为什么输出中的数字会突然跳到很大的数字?
我在C++中试过这个并且得到了相同的行为.请问有谁可以解释一下这是什么原因?
我的问题是每当我尝试使用Makefile进行编译时,我得到以下内容:
make: Warning: File `Board.c' has modification time 1.3e+03 s in the future
gcc -Wall -c -Wvla -lm Board.c -o Board.o
gcc -Wall -c -Wvla -lm PlayBoard.c -o PlayBoard.o
gcc -lm ErrorHandle.o Board.o PlayBoard.o -g -o PlayBoard
make: warning: Clock skew detected. Your build may be incomplete.
Run Code Online (Sandbox Code Playgroud)
我的Makefile是:
CC = gcc
FLAGS = -Wall -c -Wvla
PlayBoard: ErrorHandle.o Board.o PlayBoard.o
$(CC) -lm ErrorHandle.o Board.o PlayBoard.o -g -o $@
PlayBoard.o: PlayBoard.c Board.o
$(CC) $(FLAGS) -lm PlayBoard.c -o $@
Board.o : ErrorHandle.o …Run Code Online (Sandbox Code Playgroud) 我需要将命令行参数从A.exe传递给B.exe.如果A.exe与多args一样
A.exe -a="a" -b="b"'
我可以使用
BeginProcess("B.exe", **args!**)
开始B.exe.我怎样才能获得原始命令行参数
'-a="a" -b="b"'
如果我进入命令行C:myprogram myfile.txt
如何在程序中使用myfile.我是否必须扫描它或是否有任意方式访问它.
我的问题是如何在我的程序中使用myfile.txt.
int
main(){
/* So in this area how do I access the myfile.txt
to then be able to read from it./*
Run Code Online (Sandbox Code Playgroud) 假设我的C程序中有以下代码:
#include <stdio.h>
void PrintSomeMessage( char *p );
int main(int argc, char *argv[]) {
char arr[10] = "hello";
PrintSomeMessage(&arr[0]);
return 0;
}
void PrintSomeMessage(char *p)
{
printf("p: %s",p);
}
Run Code Online (Sandbox Code Playgroud)
为什么输出这个单词"hello"而不是单个字符"h"?
但我明白,如果我"%c"在格式化程序中添加一个,它只会打印一个字母.但是,此地址中每个字母的内存地址不同.请有人向我解释一下吗?
我怎样才能检查当前线程是否是linux上的主线程?看起来像gettid()只返回一个pid,但似乎linux不保证带有main()的线程总是有一个const和统一的pid.
这样做的原因是我有一个自动并行化,我想确保在已经由pthread_create()创建的线程上运行的函数中不调用pthread_create().
我是pthreads的新手,我想知道确切的差异是什么.
pthread_exit退出一个线程.因此pthread_join将返回; 但是,分离的作用与pthread_join有什么不同?
例如,我创建一个线程,并说让线程完成,我想完全终止线程,以便我以后可以重新创建它.什么是更好的使用.pthread_join还是pthread_detach?
所以执行的顺序是
pthread_exit();
pthread_join(); or pthread_detach();
Run Code Online (Sandbox Code Playgroud)
?
通常使用隐式函数返回void*转换为分配指定指针,就像malloc()一样:
void *malloc(size_t size);
int *pi = malloc(sizeof *pi);
Run Code Online (Sandbox Code Playgroud)
我希望在传递目标指针的地址时执行相同的赋值,而不从函数内部(不在其体内,也不在参数中)显式地转换其类型.
以下代码似乎实现了这一点.
.
#include <stdio.h>
#include <stdlib.h>
int allocate_memory(void *p, size_t s) {
void *pv;
if ( ( pv = malloc(s) ) == NULL ) {
fprintf(stderr, "Error: malloc();");
return -1;
}
printf("pv: %p;\n", pv);
*((void **) p) = pv;
return 0;
}
int main(void) {
int *pi = NULL;
allocate_memory(&pi, sizeof *pi);
printf("pi: %p;\n", (void *) pi);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果:
pv: 0x800103a8;
pi: 0x800103a8;
Run Code Online (Sandbox Code Playgroud) 我以为我读过某个地方,当使用指针并且我们想要将一个内容复制到另一个时,有两个选项:
然而在下面的例子中,我只是通过为两个指针分配内存来测试它,然后分配第二个,先改变..然后我的第二个指针的输入也在改变.我做错了什么:/.
typedef struct {
int a;
int b;
int c;
} my_struct;
int main(int argc, char** argv) {
my_struct* first = malloc(sizeof(my_struct));
first->a = 100; first->b = 101; first->c = 1000;
my_struct* bb = malloc(sizeof(my_struct));
printf("first %d %d %d\n", first->a, first->b, first->c);
bb = first;
printf("second %d %d %d\n", bb->a, first->b, bb->c);
first->a = 55; first->b = 55; first->c = 89;
printf("second %d %d %d\n", bb->a, first->b, bb->c);
}
Run Code Online (Sandbox Code Playgroud)