Question: Is there a correct or conventional way to guarantee a data type will be sizeof 4? 

Previously I had just done some typedef statements based upon sizeof different data types, and I was wondering if there is a better or more conventional method to have data types of a pre determined size on different architectures? 

For the sake of this question lets say I have a large array of chars that I have read from a file. I want to read a series of 24 bit Integers from this char array. In the past I have casted the array to a data type with a sizeof my desired data type, this method fails however if there is no primitive data type with my desired size. 

What is the best way to handle this situation? 

```
  char x[10] = {1,1,1,1,1,1,1,1,1,1};
  uint32_t* y = (uint32_t*)x;
  for(int i=0; i < 10; i++)std::cout << "y: " << y[i] << "\n";

  output:
  y: 16843009
  y: 16843009
  y: 257

  desired output:
  y: 65793
  y: 65793
  y: 65793
   ....

```

Answer: 
Assuming that the function is convex and the derivative of `f(x)` exist for all points => there is only one minima. The reason I am stressing the derivative constrain is that in the case when the function looks like two convex functions one next to another at the point of intersection the derivative doesn't exist, but the function is still convex and there are two local minima. 

The derivative will have opposite signs to the left and to the right of the minima (the slope changes the directions) You can see a visualization of that [here](http://en.wikipedia.org/wiki/Slope#/media/File:Tangent_function_animation.gif). Having this in mind you can do a simple binary search on your domain to find a point `k` that satisfies `f'(k-e) * f'(k+e) < 0` the smaller you pick `e`, better the precision of the result. When doing the search let `[a,b]` be the interval and `k=(a+b)/2` you would select left if `f'(k)*f'(a) < 0` and right otherwise.

Having `f(x)`, `f'(x) = (f(x+e)-f(x))/e`, again smaller you pick `e`, better the precision of the derivative.
If function is random, I think there is no way to quickly find minimum, because if f(x) can be anything (black box) there is no guarantee that this function is continuous function.

If function is convex it can be approximated with parabola.

If function is realy parabolic shape, you could tabe 6 random points and calculate its values. Every parabola could be represented by 6 points so you could calcolated its function and then calculate its minimum by derivation. This is only aproctimatin but you could prepare function of derivation ab front ( as function of 6 variables ) so you will need only 7 staps to calculate it ( depends on how complex is f(x) ) but I thing this is one of the fastest way. But again this is only a good gues of the minimum.