Storing data in an arbitrarily large data type on the stack

I have a struct of doubles like so:

Code:

struct data
{
double x;
double y;
double z;
} data;

I want to be able to store it anywhere on the stack instead of using malloc or dynamic allocation on the heap (don't ask). I wish to know what would be the best datatype to use? It doesn't have to be the precise size, only larger, because it will be used for scratching using memcpy().

No messy memcpy to get the size wrong.
No guessing the size of the scratch buffer.

> I want to be able to store it anywhere on the stack instead of using
> malloc or dynamic allocation on the heap (don't ask)
So you prefer crashes without warning because you blew the stack because 'arbitrary large' got too large?

For an embedded application (or for any application for that matter) you have to make predetermined assumptions about variable sizes. For example fixed char sizes to store strings etc, which my program is also full of.

Incidently this particular example is for a temporary scratching buffer used in a bubble sort algorithm. Yes you are hardcoding the size of scratch in advance. I don't want to assume the exact type of storage in the algorithm because I may want to use it in other parts of the program (with other types). The idea was to look for a solution such that the variable would be local (on the stack) and easily discardable but at the same time be big enough to hold the anticipated data.

qsort is part of the C std. lib.
It doesn't use malloc(). It uses a similar type approach I described above.
I would prefer to reuse a pre-existing library if I could. But I am not using qsort because qsort only accepts an array of data, and I want to sort an array of structs instead according to data in specific locations of the structs.
There is nothing wrong with bubble sort nor an embedded environment.

qsort is part of the C std. lib.
It doesn't use malloc(). It uses a similar type approach I described above.
I would prefer to reuse a pre-existing library if I could. But I am not using qsort because qsort only accepts an array of data, and I want to sort an array of structs instead according to data in specific locations of the structs.
There is nothing wrong with bubble sort nor an embedded environment.

So, you are ignorant of how qsort works!

I suggest you find out if your embedded platform has qsort and then if it does find examples of using qsort of structures.

Tim S.

"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

qsort is part of the C std. lib.
It doesn't use malloc(). It uses a similar type approach I described above.
I would prefer to reuse a pre-existing library if I could. But I am not using qsort because qsort only accepts an array of data, and I want to sort an array of structs instead according to data in specific locations of the structs.
There is nothing wrong with bubble sort nor an embedded environment.

Why are you babbling about things you obviously know absolutely nothing about? Are you a troll or just retarded?

If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

With all due respect I am not your apprentice. If you consider yourself to be in a teaching position then all you've done is to suggest workarounds to the original problem. This isn't an exercise to take a most polar opposite position possible regardless. The most effective solutions I hope you'll agree are the keep it simple stupid solutions. Now when I repeatedly said that I don't wish to specify a datatype for the storage explicitly, why am I going to make things more complicated and bundle a whole load them in a union instead?