J
J Krugman
There was a time when all I programmed was C. I thought I'd never
forget it; not the basics anyway. Therefore I find it very upsetting
that this is giving me a segfault:
#include <stdio.h>
double foo[ 2 ][ 3 ] = {{1., 2., 3.}, {4., 5., 6.}};
int main( void ) {
int i, j;
double **r;
r = foo;
for ( i = 0; i < 2; ++i ) {
for ( j = 0; j < 3; ++j ) {
printf( "%f\t", r[ i ][ j ] );
}
printf( "\n" );
}
return 0;
}
More generally, I want to pass foo as the argument to a function
bar(double **, int n_rows, int n_cols), but either bar(foo, 2, 3)
or bar((double **)foo, 2, 3) result in another segfault. I realize
that I am making an elementary mistake, but for the life of me I
can no longer see it. Please someone remind me of what I should
do.
TIA!
jill
forget it; not the basics anyway. Therefore I find it very upsetting
that this is giving me a segfault:
#include <stdio.h>
double foo[ 2 ][ 3 ] = {{1., 2., 3.}, {4., 5., 6.}};
int main( void ) {
int i, j;
double **r;
r = foo;
for ( i = 0; i < 2; ++i ) {
for ( j = 0; j < 3; ++j ) {
printf( "%f\t", r[ i ][ j ] );
}
printf( "\n" );
}
return 0;
}
More generally, I want to pass foo as the argument to a function
bar(double **, int n_rows, int n_cols), but either bar(foo, 2, 3)
or bar((double **)foo, 2, 3) result in another segfault. I realize
that I am making an elementary mistake, but for the life of me I
can no longer see it. Please someone remind me of what I should
do.
TIA!
jill