Considering this answer for the benefit of typedefs
on basic types and why they are used, is there any way to ensure that in your project you did not use a basic type and used the typedef counterparts?
In Typescript, Type assertion is a technique that informs the compiler about the type of a variable. Type assertion is similar to typecasting but it doesn't reconstruct code. You can use type assertion to specify a value's type and tell the compiler not to deduce it.
// One major difference between type aliases vs interfaces are that interfaces are open and type aliases are closed. This means you can extend an interface by declaring it a second time. // In the other case a type cannot be changed outside of its declaration.
A type guard is a TypeScript technique used to get information about the type of a variable, usually within a conditional block. Type guards are regular functions that return a boolean, taking a type and telling TypeScript if it can be narrowed down to something more specific.
If you really, absolutely want to ban native types but allow typedefs
, I guess you can always do something like:
#include <stdint.h>
#define int please_use_stdint_typedefs_rather_than_native_types
int main()
{
int32_t good; // Good typedef.
int evil; // Evil native type.
}
$ gcc -c int_forbidden.c
int_forbidden.c: In function ‘main’:
int_forbidden.c:8: error: ‘please_use_stdint_typedefs_rather_than_native_types’ undeclared (first use in this function)
int_forbidden.c:8: error: (Each undeclared identifier is reported only once
int_forbidden.c:8: error: for each function it appears in.)
int_forbidden.c:8: error: expected ‘;’ before ‘evil’
That said, I don't think outright banning native types is a good idea in the general case.
You can make these typedefs Strong Typedefs as proposed in this boost library : http://www.boost.org/doc/libs/1_40_0/boost/strong_typedef.hpp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With