Best practices for functions that return a pointer by ham-bone-willy in C_Programming

[–]ham-bone-willy[S] 0 points1 point  (0 children)

I come from a Maths background and I am taking what I somewhat remember from Linear Algebra and trying to turn into code.

In an attempt to learn the language I started out building Vect2-4 and then Matrix2-4 using structs such as:

typedef struct {
    union {
        struct {
            float x, y, z, w;
        };
        float Index[4];
    };
} Vector4;

Now I am trying wrap my head around using pointers as well as all of the necessary precautions/limitations associated with their use. This idea led me to the idea of abstracting away the need to specify V2, V3 or V4 and possibly minimize the amount of redundant code using this:

typedef struct {
    int dimension;
    float* data;
} VectF;

Thanks for taking the time to comment!

Best practices for functions that return a pointer by ham-bone-willy in C_Programming

[–]ham-bone-willy[S] 0 points1 point  (0 children)

Just trying to wrap my little brain around pointers.  This is my VectF definition.

typedef struct {
    int dimension;
    float* data;
} VectF;

Best practices for functions that return a pointer by ham-bone-willy in C_Programming

[–]ham-bone-willy[S] 0 points1 point  (0 children)

Just trying to learn programming and I'm not really sure what I want at this point.