sizeof

I2C_SLAVE ioctl purpose

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing code for implementing a simple i2c read/write function using the general linux i2c driver linux/i2c-dev.h I am confused about the ioctl : I2C_SLAVE The kernel documentation states as follows : You can do plain i2c transactions by using read(2) and write(2) calls. You do not need to pass the address byte; instead, set it through ioctl I2C_SLAVE before you try to access the device However I am using the ioctl I2C_RDWR where I again set the slave address using i2c_msg.addr . The kernel documentation also mentions the following :

C Win32: save .bmp image from HBITMAP

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working with a framegrabber and need to get the images from computer memory and save them on an image file. after trying for couple of days I end up with the following 2 functions, which creates a file and windows OS is able to run the .bmp file, but the bitmap file is black (the image size is 900KB , 640*480). does any body has any idea why, the picture is in black? here are the two functions : and here is the function for saving into .bmp : BOOL SaveToFile(HBITMAP hBitmap3, LPCTSTR lpszFileName) { HDC hDC; int iBits; WORD wBitCount;

Why is sizeof considered an operator?

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why is sizeof considered an operator and not a function? What property is necessary to qualify as an operator? 回答1: Because the C standard says so, and it gets the only vote. As consequences: The operand of sizeof can be a parenthesised type, sizeof (int) , instead of an object expression. The parentheses are unnecessary: int a; printf("%d\n", sizeof a); is perfectly fine. They're often seen, firstly because they're needed as part of a type cast expression, and secondly because sizeof has very high precedence, so sizeof a + b isn't the same

Is sizeof(size_t) == sizeof(void*) always true?

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does the C99/C++11 standard guarantee that sizeof(size_t) == sizeof(void*) is always true? size_t f(void* p) { return (size_t)(p); // Is it safe? } void* f(size_t n) { return (void*)(n); // Is it safe? } 回答1: No, that is not guaranteed. Use intptr_t or uintptr_t to safely store a pointer in an integer. There are/were architectures where it makes sense for that to be false, such as the segmented DOS memory model. There the memory was structured in 64k segments - an object could never be larger than a segment, so 16-bit size_t would be enough.

size of array passed to C++ function? [duplicate]

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Possible Duplicates: Sizeof an array in the C programming language? determine size of array if passed to function How can I get the size of a C++ array that is passed to a function? In the following code, the sizeof(p_vertData) does not return the correct size of the array. float verts[] = { -1.0,1.0,1.0, 1.0,1.0,1.0, 1.0,-1.0,1.0, -1.0,-1.0,1.0, -1.0,1.0,-1.0, 1.0,1.0,-1.0, 1.0,-1.0,-1.0, -1.0,-1.0,-1.0 }; void makeVectorData(float p_vertData[]) { int num = (sizeof(p_vertData)/sizeof(int)); cout What am I doing wrong? 回答1: You can't -

What is a common C/C++ macro to determine the size of a structure member?

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In C/C++, how do I determine the size of the member variable to a structure without needing to define a dummy variable of that structure type? Here's an example of how to do it wrong, but shows the intent: typedef struct myStruct { int x[10]; int y; } myStruct_t; const size_t sizeof_MyStruct_x = sizeof(myStruct_t.x); // error For reference, this should be how to find the size of 'x' if you first define a dummy variable: myStruct_t dummyStructVar; const size_t sizeof_MyStruct_x = sizeof(dummyStructVar.x); However, I'm hoping to avoid having

Why do I get a C malloc assertion failure?

匿名 (未验证) 提交于 2019-12-03 02:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am implementing a divide and conquer polynomial algorithm so I can benchmark it against an OpenCL implementation, but I can't get malloc to work. When I run the program, it allocates a bunch of stuff, checks some things, then sends the size/2 to the algorithm. Then when I hit the malloc line again it spits out this: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((_

Does not evaluating the expression to which sizeof is applied make it legal to dereference a null or invalid pointer inside sizeof in C++?

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: First of all, I've seen this question about C99 and the accepted answer references operand is not evaluated wording in the C99 Standard draft. I'm not sure this answer applies to C++03. There's also this question about C++ that has an accepted answer citing similar wording and also In some contexts, unevaluated operands appear. An unevaluated operand is not evaluated. wording. I have this code: int* ptr = 0; void* buffer = malloc( 10 * sizeof( *ptr ) ); The question is - is there a null pointer dereference (and so UB) inside sizeof() ? C++03

How is infinity represented in a C double?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I learned from the book Computer Systems: A Programmer's Perspective that the IEEE standard requires the double precision floating number to be represented using the following 64-bit binary format: s: 1 bit for sign exp: 11 bits for exponent frac: 52 bits for fraction The +infinity is represented as a special value with the following pattern: s = 0 all exp bits are 1 all fraction bits are 0 And I think the full 64-bit for double should be in the following order: (s)(exp)(frac) So I write the following C code to verify it: //Check the

Detecting Integer Constant Expressions in Macros

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: There was a discussion in the Linux kernel mailing list regarding a macro that tests whether its argument is an integer constant expression and is an integer constant expression itself. One particularly clever approach that does not use builtins, proposed by Martin Uecker (taking inspiration from glibc's tgmath.h ), is: #define ICE_P(x) (sizeof(int) == sizeof(*(1 ? ((void*)((x) * 0l)) : (int*)1))) This macro expands into an integer constant expression of value 1 if the argument is an integer constant expression, 0 otherwise. However, it