sizeof

Why does sizeof(*“327”) return 1 instead of 8 on a 64 bit system?

与世无争的帅哥 提交于 2019-12-03 09:43:47
printf("%lu \n", sizeof(*"327")); I always thought that size of a pointer was 8 bytes on a 64 bit system but this call keeps returning 1. Can someone provide an explanation? Putting * before a string literal will dereference the literal (as string literal are array of characters and will decay to pointer to its first element in this context). The statement printf("%zu \n", sizeof(*"327")); is equivalent to printf("%zu \n", sizeof("327"[0])); "327"[0] will give the first element of the string literal "327" , which is character '3' . Type of "327" , after decay, is of char * and after

IMFTransform interface of Color Converter DSP giving E_INVALIDARG on SetInputType/SetOutputType

匿名 (未验证) 提交于 2019-12-03 09:19:38
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use Color Converter DMO ( http://msdn.microsoft.com/en-us/library/windows/desktop/ff819079(v=vs.85).aspx ) to convert RBG24 to YV12/NV12 via Media Foundation. I've created an instance of Color Converter DSP via CLSID_CColorConvertDMO and then tried to set the needed input/output types, but the calls always return E_INVALIDARG even when using media types that are returned by GetOutputAvailableType and GetInputAvailableType . If I set the media type to NULL then i get the error that the media type is invalid, that makes sense. I

Android JNI - Reliable way to convert jstring to wchar_t

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my Android JNI code, I need to convert jstring to wchar_t. The closest reference I found was How do I convert jstring to wchar_t * . One can obtain jchar* and the length using the following code: const jchar *raw = env->GetStringChars(string, 0); jsize len = env->GetStringLength(string); wchar_t* wStr = new wchar_t[len+1]; It seems I cannot use wcncpy to copy "raw" into "wStr." Although jchar is 2-bytes long, wchar_t is 4 bytes long on all modern versions of Android OS. One option is to copy one character at a time in a for loop: for(int

Get a HBITMAP from an 24bit BMP file loaded into memory

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a 24bit BMP file loaded into RAM and I'm trying to create a HBITMAP for this image file. I have found some examples around which I've been experimenting with, but can't seem to make work. Basically, I need a HBITMAP for the file, so that I can unload the file and just keep the HBITMAP which I can dispose of later with DeleteObject(). Since this bitmap is loaded very early on in my application, there is no application Window and therefore no HDC. This is what I have so far:- HBITMAP cBitmap; // This should be where my bitmap handle

What am I missing from this K&R sample?

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The following is an excerpt from a code sample in K&R's The C Programming Language (section 8.7): typedef long Align; union header { struct { union header *ptr; unsigned size; } s; Align x; }; typedef union header Header; And here is the explanatory excerpt: To simplify alignment, all blocks are multiples of the header size, and the header is aligned properly. This is achieved by a union that contains the desired header structure and an instance of the most restrictive type, which we have arbitrarily made a long. So, as I understand it, the

size of array in c

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: a simple question that bugs me. Say I have an array defined in main like so int arr[5] . Now, if I'm still inside main and I set int i = sizeof(arr)/sizeof(arr[0]) then I is set to be 5, but if I pass the array as a function parameter and do the exact same calculation in this function, I get a different number. Why is that? At first I thought its because in a function arr is a pointer, but as far as I know arr is a pointer inside main too! Also, if I do something very similar only I initialize the array dynamically, I get weird results: int

How to multicast with ipv6 udp socket in C/C++ on linux?

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: (English is not my native tongue, don't worry if some sentences are strange ;) ). I was developing a PONG game and by the way creating some classes to help me managing window, event ... and network because I added a LAN feature to the game but currently you have to enter the address of the one with who you want to play with. And a solution to that was a broadcast (scanning LAN for player) . This was easy with ipv4, just use the address 255.255.255.255 but we are in 2017 and provide a feature that works only with ipv4 sucks... Then I look for

Why does “memset(arr, -1, sizeof(arr)/sizeof(int))” not clear an integer array to -1?

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it not possible to use memset on an array of integers? I tried the following memset call and didn't get the correct integer values in the int array. int arr[5]; memset (arr, -1, sizeof(arr)/sizeof(int)); Vaules I got are: arr[0] = -1 arr[1] = 255 arr[2] = 0 arr[3] = 0 arr[4] = 0 回答1: Just change to memset (arr, -1, sizeof(arr)); Note that for other values than 0 and -1 this would not work since memset sets the byte values for the block of memory that starts at the variable indicated by *ptr for the following num bytes. void * memset (

ARM cortex-M3 uint_fast32_t vs uint32_t

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am developing a program for an STM32Fx cortex-M3 series processor. In stdint.h the following are defined: typedef unsigned int uint_fast32_t; typedef uint32_t uint_least32_t; typedef unsigned long uint32_t; As I understand it. [u]int_fast[n]_t will give you the fastest data type of at least n bits. [u]int_least[n]_t will give you the smallest data type of at least n bits. [u]int[n]_t will give you the data type of exactly n bits. Also as far as i know sizeof(unsigned int) <= sizeof(unsigned long) and UINT_MAX <= ULONG_MAX - always. Thus I

generate random long number in C++

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We know that to generate random long number we do following steps in Java Random r=new Random() return r.nextLong(); what will be equivalent of this code in C++? like this? return (long) rand(); 回答1: <cstdlib> provides int rand(). You might want to check out the man page. If long is bigger than int on your system, you can call rand() twice and put the first value in the high word. #include <cstdlib> long lrand() { if (sizeof(int) < sizeof(long)) return (static_cast<long>(rand()) << (sizeof(int) * 8)) | rand(); return rand(); } (it's very