sizeof

Zero size struct

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I noticed that when compiled with GCC 4.6 sizeof(Foo) is 0 and sizeof(Bar) is 1. For some reason adding an empty array into an empty structure made its size 0. I thought that the sizes of both structures must be the same. What is going on here? struct Foo { char x[]; }; struct Bar {}; 回答1: Neither struct declaration is allowed by the C standard. 6.7.2.1 (8) in n1570: And paragraph 18 in the same section: As a special case, the last element of a structure with more than one named member (emphasis mine) Flexible array members are not allowed

DLL LoadCount on Windows 8

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does anyone know where LDR_MODULE.LoadCount is on windows 8? The following code always prints 6 for the reference count :S I checked with a RemoteDLLTool and the baseaddress and all other information is correct. However, LoadCount is wrong as it is always 6. I read that if it is 6, it means the DLL is loaded dynamically and if it is -1, it is static. Also is there a way I can just iterate the linked list without having to constantly ReadProcessMemory? I need to figure out the reference count somehow.. Basically the code below on Windows 7

Summing the rows of a matrix (stored in either row-major or column-major order) in CUDA

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working on the problem summing the rows of a matrix in CUDA. I'm giving the following example. Suppose to have the following 20 * 4 array: 1 2 3 4 4 1 2 3 3 4 1 2 . 1 2 3 4 . . . . . . . . 2 1 3 4 After flattened the 2d array to a 1d array (either in row-major or column-major order), I need to assign each thread to a different row and calculate the cost for that row. For example - thread 1 should calculate the cost for 1 2 3 4 - thread 2 should calculate the cost for 4 1 2 3 How can I that in CUDA? Thank you all for the reply 回答1:

C2070 - illegal sizeof operand

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The following code looks fine to me: #include <stdio.h> template <typename T> struct A { static float m_kA[]; }; template <typename T> float A<T>::m_kA[] = {1.0f, 2.0f, 3.0f}; int main() { printf("%d\n", sizeof(A<unsigned int>::m_kA) / sizeof(A<unsigned int>::m_kA[0])); return 0; } But when i compile with VC9 i get the following error error C2070: 'float []': illegal sizeof operand I would expect this code to compile. Am i missing something? Does anyone know a way to fix this strange behavior (note that the exact same thing without the

How to fix gcc error: expected while before void

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I am writing a peer-to-peer chat client that uses pthreads to manage all the IO and when I compile the file gcc gives me the error client.c: In function ‘accepted_daemon’: client.c:115:1: error: expected ‘while’ before ‘void’ void * ^ client.c: In function ‘listen_daemon’: client.c:176:1: error: expected ‘while’ before ‘int’ int main(int argc, char *argv[]) ^ The source code for my program is #include <stdlib.h> #include <string.h> #include <stdint.h> #include <errno.h> #include <assert.h> #include <unistd.h> #include <pthread.h> #include

Why sizeof(param_array) is the size of pointer?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to get the length of an array, say int array[] = {1, 2, 3, 4} . I used sizeof to do that. int length ( int array []) { return sizeof ( array ) / sizeof ( int ); } int main () { int array [] = { 1 , 2 , 3 , 4 }; printf ( "%d\n" , length ( array )); // print 1 printf ( "%d\n" , sizeof ( array ) / sizeof ( int )); // print 4 } So, why the sizeof(array) in function length returns the pointer size of array ? But in function main , it works. And, how should I modify the length function to get an array's length? 回答1: A special C

&#039;%d&#039; expects argument of type &#039;int&#039;, but argument 2 has type &#039;long unsigned int&#039; [-Wformat=] [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How can one print a size_t variable portably using the printf family? 12 answers I keep getting compile warnings but I don't know how to fix it: '%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [ The program runs fine but I still get the compile warnings: /* Sizeof.c--Program to tell byte size of the C variable */ #include <stdio.h> int main(void) { printf("\nA Char is %d bytes", sizeof( char )); printf("\nAn int is %d bytes", sizeof( int )); printf("\nA short is %d

[TJOI2017] DNA - 后缀数组,稀疏表

点点圈 提交于 2019-12-03 02:11:58
[TJOI2017] DNA Description 求模式串与主串的匹配次数,容错不超过三个字符。 Solution 枚举每个开始位置,进行暴力匹配,直到失配次数用光或者匹配成功。考虑到容错量很小,所以每个位置开始的匹配过程中大部分与普通匹配是同样操作,而我们需要的其实就是 LCP 长度,所以预处理出后缀数组和高度数组,建 ST 表支持 RMQ 询问,来加速暴力匹配的过程。时间复杂度 \(O(n \log n)\) #include <bits/stdc++.h> using namespace std; int n,k,l0,m=256,sa[250005],y[250005],u[250005],v[250005],o[250005],r[250005],h[250005],T; char str[250005]; int lg2[250005]; struct clsst { int a[250005][21]; void build(int *src,int n) { for(int i=1;i<=n;i++) a[i][0]=src[i]; for(int i=1;i<=20;i++) for(int j=1;j<=n-(1<<i)+1;j++) a[j][i]=min(a[j][i-1],a[j+(1<<(i-1))][i-1]); } int query(int l

C - allocating a matrix in a function

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to allocate a matrix using a function that takes its dimensions and a triple pointer. I have allocated an int** (set to NULL) and I am passing its address as the function's argument. That gives me a mem access violation for some reason. void allocateMatrix(int ***matrix, int row, int col) { int i; if((*matrix = (int**)malloc(row * sizeof(int*))) == NULL) { perror("There has been an error"); exit(EXIT_FAILURE); } for(i = 0; i < row; ++i) { if((*matrix[i] = (int*)malloc(col * sizeof(int))) == NULL) { perror("There has been an error

Can I share a file descriptor to another process on linux or are they local to the process?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Say I have 2 processes, ProcessA and ProcessB. If I perform int fd=open(somefile) in ProcessA, can I then pass the value of file descriptor fd over IPC to ProcessB and have it manipulate the same file? 回答1: You can pass a file descriptor to another process over unix domain sockets. Here's the code to pass such a file descriptor, taken from Unix Network Programming ssize_t write_fd(int fd, void *ptr, size_t nbytes, int sendfd) { struct msghdr msg; struct iovec iov[1]; #ifdef HAVE_MSGHDR_MSG_CONTROL union { struct cmsghdr cm; char control[CMSG