Skip to main content
Filter by
Sorted by
Tagged with
Advice
0 votes
11 replies
239 views

The following code is accepted by GCC and the resulting binary prints the expected results. But is it standard conform and would always work on different systems using different compilers? Minimal ...
Martin Fehrs's user avatar
  • 1,185
1 vote
2 answers
176 views

I've created the function void add_entry(char key[], void* value, char file[], ValueType type) and I want to use my generic function to get the typeof the pointer #define typeof(x) _Generic((x), \ ...
user31846615's user avatar
3 votes
1 answer
77 views

Suppose I create a shared memory object: from multiprocessing import shared_memory shm_a = shared_memory.SharedMemory(create=True, size=1024) buffer = shm_a.buf and put a generic object of a generic ...
Geremia's user avatar
  • 5,844
1 vote
1 answer
79 views

I have an array of pointers to structs in C as typedef struct{ int elem1; char *elem2; ... }example_t; example_t *array[MAX_SIZE]; I did generic functions for add or delete pointers to ...
Daniel Muñoz's user avatar
4 votes
1 answer
179 views

I am currently trying to make a code more safe for a cybersecurity exercise. I was asked to make the flag contained in the secret_function() come out. The problem is that I can't modify the code and ...
Tempest_Sword's user avatar
3 votes
2 answers
125 views

I have written this example to try and explain the problem. I have defined a function as follows: // Return name from given user. typedef char *(name)(void *user); And then implemented this function ...
sja785's user avatar
  • 31
1 vote
1 answer
126 views

Context I've been trying to learn C and have become a little more comfortable in it recently. I am building a 2d space shooting game (kind of Galaga inspired, written using SDL) and decided to use ...
Luke Fisher's user avatar
0 votes
1 answer
55 views

I am trying to allocate memory for certain data structures (array, matrix, custom_array, ...). The problem I think I am facing is that I am not able to cast the proper types to the passed pointers ...
Megrah Yacine's user avatar
0 votes
2 answers
121 views

I'm trying to work my way through The C Programming Language, 2nd Edition, and I can't get my head around exactly what is happening in the following code. The example from the book works just fine ...
Mike T.'s user avatar
  • 417
1 vote
1 answer
497 views

I have some legacy code that reads like this: bool has_attribute(int kvidx) const { void* v = nullptr; int flag = 0; MPI_Comm_get_attr(impl_, kvidx, &v, &flag); return flag != ...
alfC's user avatar
  • 16.8k
0 votes
5 answers
240 views

I'm a C beginner, and I've got a question while I read the Chapter 19.5 of C Programming: A Modern Approach (2nd Edition) by K. N. King. In this chapter, the author explains what is program design and ...
Doohyeon Won's user avatar
2 votes
3 answers
177 views

Setup I'm taking over code from another person. I found a coding pattern that seems odd to me. This is for an embedded 32 bit PIC processor, in case that's relevant. They have a custom typedef in a ...
Trashman's user avatar
  • 1,664
0 votes
0 answers
50 views

I'm using void pointers to handle data in arrays, and i was wondering if i could cast(?) the data in a way that doesn't pad the code. For example i have a structure: typedef struct Matrix{ int rows; ...
pasty guacamole's user avatar
0 votes
0 answers
34 views

I'm attempting to write a program that takes data from main (member type structure), then passes it to (void *) within the function, placing it on the stack in a linked list. In order to use this ...
Ratdude's user avatar
  • 93
0 votes
0 answers
31 views

I know that a void pointer is useful for setting up generic functions etc. In any case, I also understand that a void pointer can be used to directly point to things like integers etc. I suspect ...
Ratdude's user avatar
  • 93
3 votes
4 answers
132 views

I am attempting to develop a method to customize strcpy. I considered two approaches for this implementation. One method involves using memcpy, while the other involves incrementing the pointer and ...
Vishnu CS's user avatar
  • 853
1 vote
1 answer
126 views

I am studying pointers in C. Trying a bunch of things to make sure I understand how pointers work, I found something that I don't understand. Here's the snippet of the code in question: int b = 30; ...
newbie's user avatar
  • 23
0 votes
1 answer
140 views

I apologise in advance for the very long message. I am seeking expertise in order to determine if what I am doing is safe/correct, or if alternatives exists. I have a C library that can hold a user-...
Gaétan J.A.M.'s user avatar
0 votes
0 answers
86 views

I'm writing a code for task which contain only two data structure(6 queues and 4 collections). But the problem is that I do not know exactly which data structures I will need until the moment of ...
Роберт Батоян's user avatar
0 votes
1 answer
82 views

I need to create an instance of one of several data structures(for example: DynamicArray, BST, HashMap, Trie) on C language. The name of data structure read from file and then instance of data type ...
Роберт Батоян's user avatar
0 votes
1 answer
136 views

I haved to realise dynamic array in c. Here is the struct of it: typedef void (*PrintArrayElement)(const void* element); typedef struct { size_t size; size_t capacity; void** array; ...
somerandomname's user avatar
2 votes
2 answers
154 views

I'm writing a C program that applies a different type of quantization to an array depending on an environmental variable. The problem is that, I need to use the same function void foo(void* ptr, ...
Saverio Pasqualoni's user avatar
0 votes
1 answer
112 views

I am looking to implement something similar to int memcmp ( const void * ptr1, const void * ptr2, size_t num ); For comparison of numerical types such as floats, doubles and integers but with ...
Gideon Kogan's user avatar
0 votes
1 answer
93 views

I assumed that the following function can get any datatype such as float, double, long, and long long and return a correct answer. Unfortunately, it does not. Can anyone explain why? My aim is to ...
Gideon Kogan's user avatar
0 votes
1 answer
82 views

I need some help with void ** pointers. In implementing a garbage collector in C (automatic reference counting), I've found I need a special assignment operator (similar to what C++ does with std::...
rshadr's user avatar
  • 11
1 vote
1 answer
106 views

I have a function called 'bench' which accepts a function pointer that returns a void pointer (for generics). static inline unsigned long bench(void* (*funcPtr)(va_list), ...) But if I pass it a ...
Programmer_2147483647's user avatar
0 votes
0 answers
98 views

I'm new to Rust and try to implement a foreign function interface which enables C code to interact with Rust structs. The functions save results within the structs for later use. I want to compile my ...
user578943's user avatar
2 votes
4 answers
246 views

Here is what I got .. typedef struct SysInfo_P { int some_P_int; char some_P_char[10]; ... } SysInfo_P; typedef struct SysInfo_S { int some_S_int; char some_S_char[10]; ... } ...
Scott Mercer's user avatar
-2 votes
1 answer
149 views

This article lists all the different categories of pointers. I have tested the explicit conversion of different types of pointers to const void* in the following snippet (live): #include <print> ...
digito_evo's user avatar
  • 3,735
0 votes
0 answers
412 views

Let me start by mentioning that I'm aware that my solution is neither thread safe nor clean at all... but that's why I'm writing this question: I'm trying to implement a thread in a C++ class in ...
juri's user avatar
  • 1
0 votes
1 answer
345 views

I was looking a the man page for fwrite, and I was curious about the usage of restrict for the arguments as I have no seen this before. size_t fwrite(const void ptr[restrict .size * .nmemb]... what ...
user21749640's user avatar
0 votes
1 answer
112 views

I've developed a SkipList with void pointer, and probabilistic way to set the maximum level of it. those are my structs: #include <stdio.h> #include <stdlib.h> #include <time.h> ...
Trammy's user avatar
  • 11
-1 votes
1 answer
260 views

I'm trying to write an abstract struct named Shape, and I need a function in derived classes that will be counting distance from a ray origin to my shape. I use functions from here, they return float, ...
Kapibarovich Kapibarov's user avatar
1 vote
1 answer
279 views

Some libraries require a callback function takes an void *(not _Atomic void *). Is it OK to cast an _Atomic Type * to void * and cast back to use it? Like the following code: #include <stdio.h> ...
Jackoo's user avatar
  • 533
-1 votes
1 answer
72 views

I'm gonna try to keep this short. As much as I can. I have a Spell class which is mostly duration, cooldown, damage, type of damage, etc.. I have SpellManager class which is supposed to instantiate ...
crvenkapavica's user avatar
-2 votes
1 answer
219 views

i have a problem in my code when i try to use compelx structure in a generic sorting library on C lang: (you can find the complete code https://github.com/Tramontz/ASD_2023) i have a binary-merge ...
Trammy's user avatar
  • 11
-1 votes
1 answer
125 views

TL;DR is union better in terms of performance than void pointer When I was searching for Union vs void pointer performance I gone thorough this question Union versus void pointer. Many suggested to ...
widesense's user avatar
  • 120
0 votes
0 answers
54 views

This is a public member in CSpellData.h: void (CSpellData::* _vptr)(); It gets assigned a callback in the constructor, like this: _vptr = GetCallbackFromID(spell_id); where: void (CSpellData::* ...
crvenkapavica's user avatar
1 vote
3 answers
193 views

I want to import a C function in Ada. There is the C part : void Register(const void *ctxt) { saved_ctxt = ctxt; // This is a global variable } void Send_Trace(const void *ctxt, ...
A.Pissicat's user avatar
  • 3,335
1 vote
1 answer
88 views

Context: I need to create a board game with a 2D array using void***, in each slot i have to initially put a Struct "Tierra" and then in later turns i can put a Struct "Bomba" The ...
Cris's user avatar
  • 13
0 votes
1 answer
88 views

I need to make a program that reads file lines and saves them in a linked queue. I am using a library that uses a void* data field in each node. When I try to print all the lines stored, the program ...
DravStart's user avatar
1 vote
1 answer
89 views

[DllImport("SiUSBXp.dll", CharSet = CharSet.Auto, EntryPoint = "SI_GetProductStringSafe")] static extern SI_STATUS GetProductString( int dwDeviceNum, ...
Piglet's user avatar
  • 29.3k
0 votes
1 answer
227 views

A lot of books say that it is safe and the ISO goes "A pointer to void may be converted to or from a pointer to any incomplete or object type. A pointer to any incomplete or object type may be ...
alessio solari's user avatar
2 votes
1 answer
227 views

Lately, while working in C, I was developing a generic function. Here is the layout of structure: typedef struct student_{ char name[32]; int roll_no; unsigned int height; } student_t; ...
stardep's user avatar
  • 300
0 votes
1 answer
393 views

I am working on a C program that takes in a void pointer that I know for a fact points to an integer but I cant figure out how to correctly cast it to such. For example, the following will produce a ...
UnSure's user avatar
  • 148
-2 votes
2 answers
119 views

I am currently working on a complex logic, where I have a map<string,void*> with these value: string mystring[10] = {"key1","key2","keyN"}; for(string s: mystrings){...
Alessandro Savona's user avatar
0 votes
0 answers
58 views

I have an assignment in which I have to implement a doubly linked list ADT. I do not have issues with that, I created something like this: class DoublyLinkedList{ struct Node{ int value; ...
Thalia's user avatar
  • 27
0 votes
4 answers
222 views

This post shows a way to use void**s to eliminate a category of bugs related to dangling pointers (use after free, double free, etc): void freep(void **p) { if (p) { free(*p); *p = ...
404 Name Not Found's user avatar
5 votes
2 answers
725 views

I'm using a library which requires a function with a void* pointer as a parameter. I have a 2D string array and I want to pass that array through that parameter and extract it inside the function. I ...
ManWithNoName's user avatar
2 votes
3 answers
147 views

I'm a beginner in C programming, and I'm sure this question is done and solved, but I cannot find much of an answer looking around. In my program, I have this implementation of a BST (Binary Search ...
randomdood1923's user avatar

1
2 3 4 5
28