Originally Posted by
esbo
Passing around 4 gigabytes of data within a program would be bordering on insanity.
You seem to have a fundamental misunderstanding here. When you pass an array to a function, only the pointer to the first element is passed. Those 4 GB will not be copied or anything, the function will be just told where it resides.
Currently it seems that your idea is to copy and paste as many instances of the functions (with altered names) as you have files and arrays. If you want to use it in another program you'd have to copy and paste the implementation, go into the function and edit certain things.
But if it occurred to you to use function parameters, you'd never have to edit the function. Simply call it with different arguments.
Code:
int data_save(const char* filename, const int* data, int size)
{
...
if (fileptr) {
//save
return 1; //TRUE
}
else {
return 0; //FALSE
}
}
When you have put the function into a hundred different programs you will be wishing you had put the error handling in the function, otherwise you will have to write the error handling a hundred times.
If exiting the program from a hundred different places where file I/O might fail is the desired behaviour in many cases, you can write a small and simple function that calls data_save and does error handling.
Code:
void save_or_die(const char* filename, const int* data, int size)
{
if (!data_save(filename, data, size)) {
puts("\nCant creat datafile");
exit(2);
}
}
Now you'll have the best of the two worlds. You can choose whether this behaviour will be used for failures, or you can handle the failure differently if you, for example, chose to continue the program.