Sender | Message | Time |
---|---|---|
29 Jan 2023 | ||
That fails;#include <stdio.h> #include <stdlib.h> #include <string.h> int func(int **ptr) { printf("%d\n", ptr[1][2]); } int main() { int a[2][2] = { 1, 2, 3, 4 }; int **ptr = a; func(ptr); } | 05:49:33 | |
it crash segmentation fault ./a.out | 05:49:54 | |
func: 2 is not a valid index since indices start at 0. Try `ptr[0][1]` instead. | 06:54:01 | |
Index was wrong. But segmentation fault again . #include <stdio.h> #include <stdlib.h> #include <string.h> int func(int **ptr) { printf("%d\n", ptr[0][1]); } int main() { int a[2][2] = { 1, 2, 3, 4 }; int **ptr = a; func(ptr); } | 07:27:29 | |
you cannot just convert a `int [][]` into a `int **` | 09:16:49 | |
in fact, you should've gotten a warning about it | 09:17:31 | |
| 09:19:04 | |
In reply to @n_r_k:matrix.orgRight. My initial question was not on how to pass array as an argument. My question was Hi, I am trying to find a C standard document or gcc compiler guide for informations on array access using pointers . I am looking for a guide which explains how [][] and deref(*) should be used. | 13:55:16 | |
draft of the C standard can be found here | 14:00:15 | |
as for your question, a is a pointer to an array, not a pointer to pointer. | 14:01:13 | |
https://c-faq.com/aryptr/pass2dary.html | 14:04:07 | |
30 Jan 2023 | ||
13:47:49 | ||
13:50:11 | ||
13:51:51 | ||
21:28:14 | ||
1 Feb 2023 | ||
03:14:30 | ||
03:47:19 | ||
03:47:34 | ||
2 Feb 2023 | ||
11:54:18 | ||
is there any Objective C like implementation of OOP in plain C? So that one does sendmessage(obj, MSGINIT), for example? | 12:04:33 | |
In reply to @justin-mcgrath:matrix.orgOooo nasty | 14:40:06 | |
If the concern was merely "can I get this to exit the loop", this is where the context (threads over context switch due to a signal jump) matters a lot and what you want to deem as 'safety'. If the test was "Will the write to is_terminate be visible to the thread that reads from it" the answer is probably going to be 'no' to 'depends, is it x86?' and even in the x86 case, NUMA configuration and signally can really fuck with its reliability. However, the next line of questions could be 'is safe for you, the same as what we consider safe? Are you okay with it eventually being true even if the order was invalid?'. | 14:46:49 | |
In reply to @n_r_k:matrix.orgWhile I'd encourage to try and remove shared memory between threads and processes, it can be inevitable in many instances and the next step is really down to using the appropriate data structure for your use case. | 14:53:19 | |
In reply to @seba-ian:matrix.orgafaik, no. I guess to ask, why you looking for an OOP solution in C? | 14:55:07 | |
Just trying to understand what you want here and what OOP features you are looking for | 14:55:35 | |
Glib provides OOP, doesn't it? | 15:05:51 | |
Dynamic dispatch, specifically. | 15:06:19 | |
(Which I don't think C++ has) | 15:06:44 | |
an_origamian: Not sure about Glib realistically, however you can code dynamic dispatch in C it is just not a language level construct where in C++ it is | 15:29:37 | |
So I guess Sebastian Gniazdowski Are you after an OOP solution in plain C, as in, you can do OOP in C and it is plain C and compiles with any C compiler or are you after some language transformation which can be compiled by any C compiler (maybe with a plugin or some other mechanism to enable it) | 15:32:26 |