« first day (2799 days earlier)      last day (823 days later) » 

2:44 AM
142
Q: Bubble sort slower with -O3 than -O2 with GCC

anonI made a bubble sort implementation in C, and was testing its performance when I noticed that the -O3 flag made it run even slower than no flags at all! Meanwhile -O2 was making it run a lot faster as expected. Without optimisations: time ./sort 30000 ./sort 30000 1.82s user 0.00s system 99% cp...

 
 
9 hours later…
11:29 AM
Can I do something like this in ansi c?

void fun(int a[], int dim){
int arr[dim], i;
....
}
 
11:51 AM
@Curio I believe, You can't with pure C89. Even thought, GCC adds it's extension for that.
 
@Kamiccolo ASML
i start in feb
 
@Micrified woaaaa, joining over 3000 software engineers? :) and they are still using matlab sigh
 
12:25 PM
@Kamiccolo Thanks
So If I wanna create a new matrix inside a function and I know the dimensions, I need to allocate it dynamically, is it right?
int **matrix;
matrix = malloc(sizeof(int*)*r);
for(i=0;i<r;i++){
matrix[i] = malloc(sizeof(int)*c);
}
Or I can create it in the main and do it in this way:
int matrix[M][N];
fun(matrix);
So that I already have the matrix ready.
 
 
1 hour later…
1:31 PM
@Curio well, in general case, You'd make it a bit easier for the CPU and everything with just one level of indirection and malloc(sizeof(int) * r * c)
 
 
4 hours later…
5:58 PM
@Kamiccolo So I consider it just as an array of length r*c
 

« first day (2799 days earlier)      last day (823 days later) »