Saturday, January 22, 2011

Today's work.

#include <stdio.h>
//#include <float.h>
#include <stdlib.h>

//#define SIZE 1000

int main (int argc, const char * argv[]) {

int *countP, count;
int a[10000000];

count = 5;
countP = &count;
for (int i = 1; i < 100001; ++i) {
countP = countP + 1;
*countP = 4;
printf("ptr is at: %p\n", countP);

for (int i = 0; i < 10000000; ++i) {
a[i] = 1;

for (int i = 1; i < 10000000; ++i) {
if (&a[i - 1] != &a[i] - 1) {
printf("Break found\nBetween indices %d and %d\n Between addresses %p and %p", i - 1, i, &a[i - 1], &a[1]);

//printf("var is: %d | ptr is: %d", count, *countP);


This is what's left of today's work. I've been screwing around a little bit with various things, and the last thing I did in my active workspace was to play with implementing my own version of an array. All I really did was write to addresses that I shouldn't have and segfault. Then I wrote an array of like 10 million elements and segfaulted again.


RT (Panzer Time!) said...

Here's a better, easier to read version. I don't like the highlighting as much as the standard XCode highlighting, but whatever.

miranda said...

Looks a bit like coding used in MatLab.

RT (Panzer Time!) said...

Well, this isn't MATLAB. This is old-fashioned, straight C. I'd like a copy of MATLAB, but I find it more important right now to learn Objective-C.