memset

Using memset on structures in C++

Hey guys. I am working on fixing older code for my job. It is currently written in C++. They converted static allocation to dynamic but didn't edit the memsets/memcmp/memcpy. This is my first programming internship so bare with my newbe-like question. The following code is in C, but I want to have it in C++ ( I read that malloc isn't go...

memset on array of structures in C++

I have another memset question. It appears as if the code I am editing may have some issues (or it's not done the same way in different files) A::LRM las[9]; //A and LRM are both structures with BOOLS and INTS memset(&las, 0, sizeof(las)); typedef Sec SecArray[16]; SecArray rad_array; memset(rad_array, 0, sizeof(SecArray)); The secon...

C strange array behaviour

After learning that both strncmp is not what it seems to be and strlcpy not being available on my operating system (Linux), I figured I could try and write it myself. I found a quote from Ulrich Drepper, the libc maintainer, who posted an alternative to strlcpy using mempcpy. I don't have mempcpy either, but it's behaviour was easy to r...

Using memcpy/memset

When using memset or memcpy within an Obj-C program, will the compiler optimise the setting (memset) or copying (memcpy) of data into 32-bit writes or will it do it byte by byte? ...

How to use VC++ intrinsic functions w/o run-time library

I'm involved in one of those challenges where you try to produce the smallest possible binary, so I'm building my program without the C or C++ run-time libraries (RTL). I don't link to the DLL version or the static version. I don't even #include the header files. I have this working fine. Some RTL functions, like memset(), can be use...

is memset(ary,0,length) a portable way of inputting zero in double array

Possible Duplicate: What is faster/prefered memset or for loop to zero out an array of doubles The following code uses memset to set all the bits to zero int length = 5; double *array = (double *) malloc(sizeof(double)*length); memset(array,0,sizeof(double)*length); for(int i=0;i<length;i++) if(array[i]!=0.0) fprintf(st...

What is the easiest way to set the value of an entire array?

My current project requires me to fill an array based upon some other values. I know there's the shortcut: int arr[4][4] = { {0,0,0,0} , {0,0,0,0} , {0,0,0,0} , {0,0,0,0} }; But in this case, I need to fill the array after its declaration. I currently have my code formatted like this: int arr[4][4]; if(someothervariable == 1){ ar...

Objective-C initial values of created C-array

I create an array, similar to classic C (not NSArray or one of it's children) - something like BOOL i[5];. And I want to make all its values to be equal to NO. First of all, I didn't found any information about initial values of such arrays (I know that in classic C they will be undefined, but don't know exactly about Objective-C. I fou...

"Use of uninitialised value" despite of memset

Hi there, I allocate a 2d array and use memset to fill it with zeros. #include<stdio.h> #include<string.h> #include<stdlib.h> void main() { int m=10; int n =10; int **array_2d; array_2d = (int**) malloc(m*sizeof(int*)); if(array_2d==NULL) { printf("\n Could not malloc 2d array \n"); exit(1); } ...

memset causes exception when pinvoke

I am using pinvoke to call functions from sslscan tool based on openssl; I checked by hit and trial that where exception is occuring is due to memset. It runs fine when i run it natively in VS.but using pinvoke causes this exception in c#.Its System.AccessViolation Exception. These are the declarations: struct sslCheckOptions options;...

How to memset() memory to a certain pattern instead of a single byte?

I am facing today with a problem where I need to change memory to a certain pattern like 0x11223344, so that the whole memory looks like (in hex): 1122334411223344112233441122334411223344112233441122334411223344... I can't figure out how to do it with memset() because it takes only a single byte, not 4 bytes. Any ideas? Thanks, Boda...

intializing a structure array using memset

Hello, gcc 4.4.4 c89 I have the following structure. struct device_sys { char device[STRING_SIZE]; int id; char category; }; int main(void) { struct device_sys dev_sys[NUM_DEVICES]; memset(dev_sys, 0, (size_t)NUM_DEVICES * sizeof(dev_sys)); return 0; } I get a stack dump when I call memset. Is this not th...

first parameter in memset passing array or pointer

Hello, gcc 4.4.4 c89 Pointers are not the same as arrays. But arrays can decay into pointers. I was just using memset which first parameter is a pointer. I would like to initialize my structure array. i.e. struct devices { char name[STRING_SIZE]; size_t profile; char catagory; }; struct devices dev[NUM_DEVICES]; memse...

Pass pointer to guaranteed zeroed memory

I need to zero records of varying sizes in a file. To do this, I'm currently allocating dummy records, memseting them to zero, and passing these to a write function. Is there some region which is guaranteed to always be zeroed (and of a large enough size), that I can instead point to, removing the need for repeated allocation and zeroin...

How portable is code using wmemset()?

Currently our code uses a for-loop for filling a buffer holding a Unicode string with some Unicode character value (of type wchar_t). There's wmemset() function in Visual C++ using which we could replace a loop with a single function call in that code. However we're concerned about portability - we'd like to leave code as portable as pos...