>>6
array of anything isn't a solution because you should declare its size so it cannot be arbitrary. personally i would just make a linked list with an array as cargo, malloc and pointers are so annoying though -_-
Name:
Anonymous2013-03-07 21:33
#define ARRAY_LENGTH 20
int **array_of_arrays(int n) {
int i;
int **array_of_arrays = malloc(sizeof(int *) * n);
for(i = 0; i < n; i++) {
array_of_arrays[i] = malloc(sizeof(int) * ARRAY_LENGTH);
}
return array_of_arrays;
}
"retard-kun" is a noun and so is "asstarded lsd trips"
But retard-kun is a person too, he can post on /prog/. But asstarded lsd trips can't post, they aren't persons; they aren't even physical! Nor are they Ai or bots. asstarded lsd trips can't do anything, they are just something a person feels!
Name:
Anonymous2013-03-07 21:54
#define nigg_arr int* /* ??? is typedef a part of C proper? I always just compile as C++ ??? */
#define runloop 1 /* set to zero to disable the loop */ /* Useful for debugging */
nigg_arr niggers; /* new nigger pointer */
int dickSizeInInches=sizeof(nigg_arr); /* will vary among machines, but should be compiled to constant */
int currentNiggerNumber=0; /* the niggers we will work on first */
niggers = (nigg_arr)malloc(numberOfNiggerDicks*dickSizeInInches); /* make a list of niggers */
do{ /* loop so that we don't test test condition first, saving time on a damn cmp instruction */
/* pointer to addr of this nigger */ *(niggers+currentNiggerNumber)=(nigg_arr)malloc(9*dickSizeInInches); /* make a list from each element in the list */
switch(currentNiggerNumber){ /* logic to decide if we are done */
numberOfNiggerDicks: /* yup, done */
/* considered harmful */ goto ALL_NIGGERS_TAGGED; /* now we can go */
default: /* not done */
/* could also be in ++ notation */ currentNiggerNumber=currentNiggerNumber+1; /* put the next nigger on the operating table :) */
} /* closes the switch loop */
}/* closes the while loop */
/* this is ternary notation BTW */ while(1==((runloop==1)?1:0)); /* test conditions for the main program loop */
ALL_NIGGERS_TAGGED: /* label for where we need to go when we finish, in this case, outside of the loop */
exit(0); /* we're done here guys, let's go home! */
well, c isn't my forte (that array raping which you suggested...) but i'm not retard kun
i like ^^ emoticon too though (so cute) but i don't use it to avoid being confused with him
int **alloc2d(size_t m, size_t n)
{
size_t vectorsz, rowsz;
int **vector;
int *row;
int i;
vectorsz = m * sizeof(int *);
rowsz = n * sizeof(int);
if (!(vector = malloc((vectorsz + m * rowsz))))
return NULL;
row = (int *) (vector + m);
for (i = 0; i < m; ++i) {
vector[i] = row;
row += n;
}
return vector;
}
Name:
Anonymous2013-03-08 1:08
check 'em
Name:
Anonymous2013-03-08 2:00
>>18
It annoys me how you think your solution better than >>9, enough to give poor >>9-san the insulting ``muh heap fragmentation'' when the solution presented in >>18, while somewhat clever, is just as deserving of insult, as it uses a trick to solve a problem that doesn't need to be solved. In other words, the problem is man made, and created by the author of >>18. So commonly do I see this pattern of chastising the efforts of others in comparison to your own imperfect work that I see on /g/, and it makes me think that you frequent this other board. But I cannot know for certain.
>>8
This should be valid C99 int myfunc(int x, int y, int arr[x][y]) {
int k = 0;
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
k += arr[i][j];
}
Name:
Anonymous2013-03-08 3:52
oh.. yes, you can do stuff like
int x, y;
scanf("%d", &x);
scanf("%d", &y);
int arr[x][y];
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
arr[i][j] = 1;
Name:
Anonymous2013-03-08 3:54
malloc (sx * sy * sizeof(datatype));
Access with e.g. arr[(y*sx)+x]
Memory is not 2D so (especially in C) you shouldn't pretend it is.
Name:
Anonymous2013-03-08 8:03
>>18
Dude OP is probably a student. If he actually gave a shit about heap fragmentation, he'd already know how to solve this problem and wouldn't be asking us. Keep it simple for the kid.
>>20,24 >>18 is too clever by half - resizing that Iliffe vector will be painful, and if you really cared that much about performance you'd probably limit the dimensions to a power of 2 anyway. This is /prog/; did you really think I was trying to help him?
Name:
Anonymous2013-03-08 11:37
>>20
Please elaborate on why the problem doesn't need to be solved.
Name:
Anonymous2013-03-08 13:43
>>20 >>9 sucks because it makes n + 1 calls to malloc. That means you'll probably need to make n + 1 calls to free as well, if you're writing a large program and you don't want it to leak like shit. Those calls are all fairly expensive, and making fewer calls to malloc that request a larger size is usually faster and it results in more compact code.
>>18 sucks too though, because it doesn't take alignment requirements into account. Although, that can be fixed with >>26.