What does the age of the compiler have to do with this? Maybe I'm writing for a 16-bit embedded processor. A 16-bit embedded processor that sorts pancake quantities, but still.
EDIT:
ISO forbids it.
wat. Cite section and paragraph of the standard, please.
The most common source of confusion are the sizes of the integer types, and the range of values which they can hold. That is because the languages leave many features of the integer types implementation-defined, meaning that it is up to the particular compiler to determine their exact specifications. C and C++ do set minimum requirements for each of the integer types, but the compiler is free to exceed these limits.
and in the Long Int section you can see:
The long types must contain at least 32 bits to hold the required range of values.
3.9.1 Fundamental types
...
There are four signed integer types: “signed char”, “short int”, “int”, and “long int.” In this
list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural
size suggested by the architecture of the execution environment39) ; the other signed integer types are provided to meet special needs. 39) that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header <climits>.
18.2 Implementation properties
The headers <limits>, <climits>, and <cfloat> supply characteristics of implementation dependent fundamental types (3.9.1).
18.2.2 C Library
Header <climits>
The contents are the same as the Standard C library header <limits.h>
Edit:
Standard C library = The library described in clause 7 of ISO/IEC 9899:1990 (I don't think I have the C90 standard)
Well, if it were me I'd stick to using a struct. I wouldn't recommend writing code that depends on the number of bytes in any particular type. The OP probably abandoned this thread a while ago. If the OP were to respond and post some more code or information about what he or she wants to do then maybe the argument would be worth while.
From what i have now read i gather that when you create a vector if its say v(9) for example this is not the same as an array in that the vector would have only 9 elements 1-9 whereas the array starts from 0 so 0-9 is 10. I am so stupid, no wonder have of it didnt work. Vectors access from 1 - arrays from 0. I thought they were both the same.
Thank you all for clearing this up, i am now one step ahead than i was before. I know that the number of the array will still lose its original value when i use the sorting alg so i have to go down a different route for the solution to pancake glutt, however just understanding this has lifted a great weight of wtf off my shoulders.
vector<int> my_vector(n); and int my_array[n];both declare containers for n integers that can be accessed with indexes (or indices if you like it better) from 0 to n-1
Somarl, in the original example you created a vector of 9 elements but tried to access it using index 9 which is out of range. So as m4ster r0shi points out, a vector and a C-array are indexed in the same way when using operator[]. I'm not sure where you got the idea that a vector is indexed starting at 1. Re-read the examples that I posted with embedded constants.