Category "pointers"

In plain C, could we implement generic functions using pointers to char instead of pointers to void?

In plain C, pointers to void are useful as arguments to generic functions, such as a generic quicksort, or a generic swap, etc., as seen here: Implementation of

Why are function pointers and data pointers incompatible in C/C++?

I have read that converting a function pointer to a data pointer and vice versa works on most platforms but is not guaranteed to work. Why is this the case? Sho

Cannot restart typedef'd 2D array whose address is saved in struct

I have this typedef and struct: typedef double mat[MAT_SIZE][MAT_SIZE]; typedef struct matList { char *name; mat *matrix; } matList; and I create an a

Why macros and functions work differently about same code in c

I am new to programing, and I found one interesting but difficult to find reason problem, so I am writing this post. I was trying to write swap function: When I

How to avoid poorly optimized code for Fortran array pointers?

I get rather poorly optimized assembly with gfortran 11.2 when using array pointers, even in seemingly very simple cases. For example, the optimized code (https

With arrays, why is it the case that a[5] == 5[a]?

As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Jo

Understanding Scope / Copy in Python Classes where arguments default to numpy vectors

I have a pretty simple python-3 code that is puzzling me. test.py : import numpy as np class PARTICLE: def __init__(self, PosV = np.zeros(3), Mass=0):

Does `offsetof(struct Derived, super.x) == offsetof(struct Base, x)` hold true in C?

I am unsure what André Caron means here: Virtual functions in C ... some of this code relies on (officially) non-standard behavior that "just happens" t

C++ How to create a constant pointer to a function?

I want to have a class with a constant pointer to a function as a member. However, I'm instead creating functions with constant return values (a strange feature

cannot convert 'LinkedList::filter(void (*)(Node*))::<lambda(Node*)>' to 'void (*)(Node*)'

Im trying to implement a simple LinkedList class, but this error shows up and I don't understand why. struct Node { public: int val; Node* next; Nod

stack smashing detected when trying to get to typedef two dinatial array that the adress store inside struct

i have this typedef of two dinantial array, and strust the keep his adress typedef double mat[MAT_SIZE][MAT_SIZE]; typedef struct matList { char *name;

React: How to pass a pointer to one component to a second component

How can you pass a pointer to component 1 to component 2 (so that you can work with component 1 inside component 2, e.g. get its properties) <Component1 />

find elements of an array in another array, why do I have this error?

I was trying to visualize the algorithm of this exercise, but I'm having a lot of problems. the exercise asks to implement this function: extern const void *mem

Location of methods in memory [duplicate]

I am new in Go world, the question could be obvious. Let's say I have a struct Example, which has some methods: type Example struct {} func (

Cython: Assign pointer values, not the pointer itself

C/C++ allows assigning values of a pointer to another pointer of the same type: #include <iostream> using namespace std; int main() { int* a = new i

Using qsort to sort a multidimensional array of variable-length strings in C

I have a piece of software that generates a rather large text file full of information about files in a directory. There are often several thousand files. Each

Is it possible to determine if a pointer points to a valid object, and if so how? [duplicate]

I was reading C++ Is it possible to determine whether a pointer points to a valid object? and the correct answer in this thread is that no, yo

Why not possible to fill any integer straight to a pointer variable?

#include <stdio.h> int main(void) { int* ptr = NULL; *ptr = 10; printf("%d", *ptr); return 0; } I am very new to C programming and sorry

Weird bug in pointers

I was trying to access single bytes of an int value via the code below. My problem is that whenever I try to remove long int i=0; from the code, it gives me a s

Invalid Initializer When I try to call function from another function

I have two functions. One that returns the part of the string for me. Don't ask me why I'm doing it inside a function because I want to run this inside a thread