5/26/2023 0 Comments Easy vector codeThese macros allow you to have more control over how you initialize a new element of a vector. To get around this, there's a set of special macros defined for both the Visual Studio compiler and compilers that support the typeof operator. If you have a vector storing some kind of structure, you can't initialize new elements of the vector like you would a variable, e.g. Unfortunatley, this also means you won't get an error when passing incorrect types to these macros, so if you're getting segfaults, make sure you are properly using vec and &vec for their corresponding calls. Get the amount of allocated memory in vec_aīecause the Visual Studio C compiler doesn't support the typeof operator, which is used for static type checks in the library's macros, you have to use a slightly different set of macros. You should get an error if you use the vector address incorrectly. vec, while other functions can change the vector's memory location and thus require the pointer address, e.g. Some functions take a normal vector argument, e.g. Here is a cheat sheet for this library's functions and macros: The reccomended way to differentiate between vectors and arrays is to simply name them differently, for example, an array of eggs could be named eggs while a vector of eggs could be named egg_vec. Vec.h already includes an alias for int* and char* types ( vec_int and vec_char respectively), but you can add as many as you want :) Typedef float* vec_float // vector alias for float Here is an example using a function that reassigns the vector pointer: This obviously means that you can't reference the same vector in multiple places without encapsulating it in some kind of structure, which is likely your intention anyway. This is my personal library of code that is common to my different projects. This means that the library calls that increase the vector's size need to take the address of the vector pointer, e.g &vec, so it can be reassigned. IconVG is a compact, binary format for simple vector graphics: icons, logos. Since the header data is stored in the same location as the the vector's elements, the entire vector might be moved to a new location when its size is changed. When you scale a vector image file, it isnt low resolution and theres no loss of quality, so it can be sized to however large or small you need it to be. These graphics are points, lines, curves and shapes that are based on mathematical formulas. Just because these vectors can be accessed and modified like regular arrays doesn't mean they should be treated the same in all cases.īecause of the hidden header data, these vectors can only be properly freed by calling vector_free(vec). What is vector artwork Vector artwork is art thats made up of vector graphics. If you're using this library for a C++ project, you can swap each occurrence of typeof with decltype, which is standardized in C++. The type checks are done using GCC's typeof operator, which is only implemented in some compilers, such as Clang and GCC, and will not work under the Visual Studio C compiler. This library uses the preprocessor to perform compile-time type checks, which make sure the pointer type of a vector corresponds to the type of its contents. This design was inspired by anitrez's Simple Dynamic Strings.
0 Comments
Leave a Reply. |