memcpy

Do any compilers transfer effective type through memcpy/memmove

我的未来我决定 提交于 2019-12-14 03:41:56
问题 According to N1570 6.5/6: If a value is copied into an object having no declared type using memcpy or memmove, or is copied as an array of character type, then the effective type of the modified object for that access and for subsequent accesses that do not modify the value is the effective type of the object from which the value is copied, if it has one. That would suggest that even on a system where "long" and some other integer type have the same representation, the following would invoke

Why the free in line2 makes memcpy do nothing?? Is free before malloc is o.k?? [closed]

旧城冷巷雨未停 提交于 2019-12-14 03:38:13
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . void str_cpy(char **des,char* src){ if(*des || *des==src) free(*des); *des = (char*)malloc(sizeof(char)*(strlen(src)+1)); if(!*des) return ; memcpy ( *des, src, (strlen(src)+1)*sizeof(char) ); } Why the free in

Function that copies a 3d array in C?

蓝咒 提交于 2019-12-14 03:31:27
问题 Hi I stumbled upon a question in my textbook that states: 'Write a function that makes a copy of the contents of a 3D array of integers. The function should support any 3D array size.' After discussing it with my lecturer he specified that the prototype of the function should look something similar to this (this is 2D, I need 3D). int sum2d(int rows, int cols, int ar[rows][cols]); Now how I currently coded it is by making everything in the main function and it works like it should, i.e copies

Why the free in line2 makes memcpy do nothing?? Is free before malloc is o.k?? [closed]

心不动则不痛 提交于 2019-12-14 00:13:58
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . void str_cpy(char **des,char* src){ if(*des || *des==src) free(*des); *des = (char*)malloc(sizeof(char)*(strlen(src)+1)); if(!*des) return ; memcpy ( *des, src, (strlen(src)+1)*sizeof(char) ); } Why the free in

Copying array of structs with memcpy vs direct approach [duplicate]

你说的曾经没有我的故事 提交于 2019-12-13 19:59:06
问题 This question already has an answer here : memcpy vs assignment in C (1 answer) Closed 6 years ago . Suppose pp is a pointer to an array of structs of length n. [was dynamically allocated] Suppose I want to create a copy of that array of structs and make a pointer to it, the following way: struct someStruct* pp2 = malloc(_appropriate_size_); memcpy(pp2, pp, _appropriate_length_); I also can make a loop and do pp2[i]=pp[i] for 0 <= i <= n . What is the difference between these approaches, and

Why does the restrict qualifier still allow memcpy to access overlapping memory?

倖福魔咒の 提交于 2019-12-13 17:28:49
问题 I wanted to see if restrict would prevent memcpy from accessing overlapping memory. The memcpy function copies n bytes from memory area src to memory area dest directly . The memory areas should not overlap. memmove uses a buffer so there is no risk of overlapping memory. The restrict qualifier says that for the lifetime of the pointer, only the pointer itself or a value directly from it (such as pointer + n ) will have access to the data of that object. If the declaration of intent is not

is there a Python Equivalent to Memcpy

杀马特。学长 韩版系。学妹 提交于 2019-12-13 13:30:29
问题 I am trying to port some C Code but I am really stuck cause of the use of memcpy I tried with ctypes (did not work). I am hoping to find a python way of using an equivalent function of memcpy Any ideas Here is an example of the C Code I am trying to port i = l + 5; t = htons(atoi(port)); memcpy((buf+i), &t, 2); 回答1: You almost certainly don't need to call htons and then copy the 2 bytes into a buffer—see Keith's answer for why. However, if you do need to do this (maybe you're crafting IP

Go- Copy all common fields between structs

情到浓时终转凉″ 提交于 2019-12-13 12:24:30
问题 I have a database that stores JSON, and a server that provides an external API to whereby through an HTTP post, values in this database can be changed. The database is used by different processes internally, and as such have a common naming scheme. The keys the customer sees are different, but map 1:1 with the keys in the database (there are unexposed keys). For example: This is in the database: { "bit_size": 8, "secret_key": false } And this is presented to the client: { "num_bits": 8 } The

Forcing GCC to perform loop unswitching of memcpy runtime size checks?

三世轮回 提交于 2019-12-13 12:23:34
问题 Is there any reliable way to force GCC (or any compiler) to factor out runtime size checks in memcpy() outside of a loop (where that size is not compile-time constant, but constant within that loop), specializing the loop for each relevant size range rather than repeatedly checking the size within it? This is an test case reduced down from a performance regression reported here for an open source library designed for efficient in-memory analysis of large data sets. (The regression happens to

Copy 6 byte array to long long integer variable

独自空忆成欢 提交于 2019-12-13 09:14:37
问题 I have read from memory a 6 byte unsigned char array. The endianess is Big Endian here. Now I want to assign the value that is stored in the array to an integer variable. I assume this has to be long long since it must contain up to 6 bytes. At the moment I am assigning it this way: unsigned char aFoo[6]; long long nBar; // read values to aFoo[]... // aFoo[0]: 0x00 // aFoo[1]: 0x00 // aFoo[2]: 0x00 // aFoo[3]: 0x00 // aFoo[4]: 0x26 // aFoo[5]: 0x8e nBar = (aFoo[0] << 64) + (aFoo[1] << 32) +