Click here to Skip to main content
16,022,131 members

Comments by Maarten ten Velden (Top 5 by date)

Maarten ten Velden 7-Mar-24 9:26am View    
Linux was written as an implementation of unix if I understand correct. Porting it to unix wouldn't be impossible hence. Some tools such as apt are not even linux specific. Apt is debian specific.

My question was not about "who currently holds ownership", it is about that the project has "Linus" on the banner because linux was named after Linus Torvalds + unix.
Maarten ten Velden 19-Jan-24 8:14am View    
Outputting *a as %d here seems wrong as *a is %p. Doing *a++ is also wrong, I think this would increment a (as postfix ++ operator has higher precedence than * increments a not *a, though *a before increment is still supplied to printf) in steps of sizeof(int*), thus on 64 bit platform (with 32 bit int) would output (? to indicate unknown/undefined value)..
a = 0x?, *a = 1
a = 0x?, *a = 5
a = 0x?, *a = 9
a = 0x?, *a = ?
a = 0x?, *a = ?
Maarten ten Velden 18-Jan-24 7:38am View    
You are talking about a multidimensional array though, I am using a non multidimensional array. The problem in your example is that ptr[1] results in a int* and then ptr[1][1] tries to dereference a pointer whereas mat[1][1] calculates an offset right?

My case with a non multidimensional array also causes an error -1073741819, which I assume is STATUS_ACCESS_VIOLATION (thus the segmentation fault you mentioned). Alignment shouldn't be a problem as I am not using a multidimensional array?

I think I do understand now why this doesn't work. I wrote my own solution.
Maarten ten Velden 17-Jan-24 8:53am View    
I didn't mean avoiding malloc and free in general, I meant in this particular case for which I am asking the question.

The following is the workaround I meant which compiles..

int** a;
int b[5];
int* c = b;
a = &c;
(*a)[1] = 123;
printf("b[1] == %i\n", (*a)[1]);


The cases you mention seem to be arbitrary rules, as though printf("%u\n", *b) doesn't work, printf("%u\n", b[0]) and int* c = b; printf("%u\n", c); would both achieve the exact same. The last example is entirely different than taking the address of an array, which is a variable, as there you are taking the address of an intermediate result. I still don't see a reason why a C compiler would not be able to directly use the & and * operators on an array.
Maarten ten Velden 17-Jan-24 7:57am View    
Well avoiding malloc and free is wanted. You said "justifiably". How is this "justifiably"? I can work around it by assigning b to an int* and then assigning the address of that int* to a, but I don't see why that is workaround is required.