| Computing desk | ||
|---|---|---|
| < February 11 | << Jan | February | Mar >> | February 13 > |
| Welcome to the Wikipedia Computing Reference Desk Archives |
|---|
| The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
How can I get out of this typewriter-font preview mode back to the previous one, which was much easier to read?
Also, why does the display/appearance of everything on WP look sketchy today? (Other websites look normal.)
Sca (talk) 13:55, 12 February 2015 (UTC)
-- [[User:Edokter]] {{talk}} 16:06, 12 February 2015 (UTC)
Done — Preview font still looks weird (for one thing, dashes & hyphs aren't visible). Sca (talk) 17:11, 12 February 2015 (UTC)
With something like Code::Blocks, the path to a runtime error from memory corruption seems incredibly easy:
int a[5];
a[5] = 2;
I understand that the lack of checking speeds things up, but I feel like this must compromise overall security. I mean (purely hypothetical example), if you download some pristine freeware program to do weather prediction or genome analysis and it accepts up to 100 sets of custom parameters from some data file it uses (never expecting more than 2 or 3 to really happen, so never bothering to test the extreme), and the wrong person sends you a data file with 100,000 sets that your freeware dutifully embeds into its array, I'd think you'd end up executing malicious code. How often does that happen, anyway? Wnt (talk) 21:30, 12 February 2015 (UTC)
char * cp = malloc(sizeof(char)*10);
cp[12] = 'f';
int a[5]; is called an array, even if Finlay is right that it doesn't have the properties that he feels a "real" array should have. And its size is available at compile time as sizeof a if you want it in bytes, and as sizeof a/sizeof(int) or sizeof a/sizeof a[0] if you want the number of elements. What you can't do in C is create an array whose size is determined at run time; you can only get a block of memory (using malloc) and access it (using a pointer) as if it was an array. (Which likewise means you can't use sizeof to find out how big it is.) Also, you can't pass an array by value to a function; you pass a pointer to the first element. (Which again means you can't use sizeof inside the function to find out how big the array is.)q[i] to access an array elements no matter whether q is the array itself or a pointer to its first element. Also, similarly, an array-like syntax can be used to declare pointers. This is intended as a convenience for the programmer; it does not mean that an array type is not a type of its own, distinct from pointers.malloc. But my basic points about terminology and sizeof haven't changed. --70.49.169.244 (talk) 09:11, 13 February 2015 (UTC)int a[5]; a[5] = 2;, I often declare C arrays one larger than needed. A compiler would also be free to automatically reserve space for one more element than declared in suitable conditions (like elements which aren't huge and arrays which aren't allocated a large number of times), but I don't know whether any do. PrimeHunter (talk) 23:47, 12 February 2015 (UTC)
P points to the i-th element of an array object, the expressions (P)+N ... and (P)-N (where N has the value n) point to, respectively, the i+n-th and i−n-th elements of the array, provided they exist... If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined." Section 6.5.2.1, Array Subscripting, defines [...] in such a way that the same rules apply to P[N].int *p; for (p = &a[0]; p < &a[n]; ++p), where n is the size of the array. Then *p will access each element of the array in turn. Here &a[n] is a one-past-the-end pointer, but you aren't ever accessing a[n] itself, which would be an error, you're just taking its address. (By the way, if you have two pointers that don't point to elements of the same array or larger structure, it's also undefined behavior if you simply compare them with something like if (p1 < p2). You are allowed to compare them for equality, though.)arr[x] syntax or bounds-checked arr.at(x) syntax, and functions to iterate over it and get its size.-gadfium 21:16, 13 February 2015 (UTC)
std::get<2>(arr) access for C++11 arrays.-gadfium 21:26, 13 February 2015 (UTC)