Questions tagged [memmove]

memmove() is a C standard library function to copy a block of memory. It work even if the source and the destination overlap.

144 questions
1
vote
1 answer

For deleting a node in a linked list if I use memmove() (in C) will it be more efficient?

Every example I encountered in internet about deleting a node in a linked list, they use this method for deleting the first node: Algorithm to delete first node of Singly Linked List %%Input: head of the linked list Begin: If (head != NULL)…
Sanaf
  • 336
  • 3
  • 13
1
vote
3 answers

Problems with implementing memmove in c

I am trying to implement the memmove() function for a certain quiz, so I dynamically allocated a block of memory with the ptr buffer as temp holder in the swap operation and the swap is done in one loop. When I submit this code it gives me one wrong…
1
vote
1 answer

Is std::memmove always safe between the same object

Is it always safe to std::memmove between the same object instances (including subobjects). That is, is the following safe for any T and any t, and will it leave t unchanged: template void maybe_copy(T& t) { std::memmove(&t, &t,…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
1
vote
3 answers

How does memmove on array of pointers in C/C++ work?

I have an array of array like this : double **Arr = malloc(N*sizeof(double*)); for(int j = 0; j < N-1; j++) Arr[j] = malloc(M*sizeof(double)) Theses arrays are full of values. And I want to shift some arrays (the N-i last ones). Are there any…
1
vote
1 answer

Clang compiler auto-changed strcpy to memmov. macOS

When I compile with Clang on macOS (with or without xCode), the call into strcpy is auto-substituted to memmov. Is there a Clang flag to turn this off? int main(void) { char nice_message[6]; const char *message = "hello"; …
rustyMagnet
  • 3,479
  • 1
  • 31
  • 41
1
vote
3 answers

Shift elements by one index with memmove

I am trying to shift the elements in a dynamically created 3d array by one index, so that each element [i][j][k] should be on [i+1][j][k]. This is how my array creation looks like typedef struct stencil{ int ***arr; int l; int m; int…
Schueni1
  • 13
  • 4
1
vote
3 answers

Remove a substring from a string with memmove in C

I'm trying to implement a function for removing a substring from a string with memmove. When printing out the results, it seems like I have not moved correctly the substrings, even though it seems like I used the correct position in the source…
ILG
  • 15
  • 4
1
vote
2 answers

Generic stack push error

Im trying to create a generic stack. I have a problem when i try to push a value into the stack, the programm crashes in the memmove line: typedef struct s_node{ void *info; struct s_node *next; }t_node; typedef struct{ char name[50]; …
user7100805
1
vote
1 answer

How to move 2 elements from head into given position in vector

I want to move the first 2 elements to given position in vector, the result is not right by using memmove in following code: vector v{1, 2, 3, 4, 0}; memmove(&(v[3]), &(v[0]), 2); The result by doing so is 1, 2, 3, 1, 0, while the expectation…
vinllen
  • 1,369
  • 2
  • 18
  • 36
1
vote
5 answers

Remove first few characters from a string

I need to remove the first 3 characters from an array without any libraries. How would I go about doing this? I know that I can use memmove but I'm working on a system without the standard library, also memmove is for pointers. With memmove I can do…
user7143217
1
vote
4 answers

Using memmove to initialize entire object in constructor in C++

Is it safe to use memmove/memcpy to initialize an object with constructor parameters? No-one seems to use this method but it works fine when I tried it. Does parameters being passed in a stack cause problems? Say I have a class foo as follows, class…
user6616617
1
vote
0 answers

Creating numpy array from ctypes POINTER using ctypes.memmove() gives wrong results

I am using ctypes to call a C++ function and calculate homography. Then it was converted into a numpy array. The homography printed in C++ is correct. However, in python it's totally wrong after converting to numpy array using ctypes.memmove(). For…
Chao Wang
  • 398
  • 1
  • 4
  • 11
1
vote
2 answers

Strange behavior of memcpy/memmove

I have the problem that memcpy/memmove change the pointer of a struct FOO foo, which is neither src nor destination of the function. Here are the gdb outputs: Before memmove(y,y_temp,size_y);: (gdb) p y $38 = 0xbff7a2e0 (gdb) p y_temp $39 = (float…
Framester
  • 33,341
  • 51
  • 130
  • 192
1
vote
0 answers

Inserting a value on a specific position in an arrayList

So I am trying to add a specific value to the arraylist.The program works but when I check if the value was added i get the same number everytime. void arrayListInsert(struct ArrayList * list, unsigned index, short value){ if(index >…
1
vote
2 answers

Unwanted spaces in the output file

I am trying to create a function that appends !! at the very end of each line from(inclusive)-to(exclusive) of a text file. After I had several complications I actually succeeded. But not entirely. int incldue_auto (char *script, unsigned int…
Imobilis
  • 1,475
  • 8
  • 29