typedef

Best Practices: Should I create a typedef for byte in C or C++?

The title pretty much says it all, do you prefer to see something like t_byte* (where t_byte would be a typedef for unsigned char) or unsigned char* in code? I'm leaning towards t_byte in my own libraries, but have never worked on a large project where this approach was taken, and am wondering about pitfalls. Regards, Dan O. ...

typedef'ing an array vs. using a struct in C++

Found an interesting use of a typedef that I really didn't see the need for. typedef int Color[3]; So then the use would be: Color pants; pants[0] = 0; etc. Using the typedef through ptrs was creating strange looking code that wasn't clear. Why not just use a struct? struct Color { int r; int g; int b; }; Color pants; pants.r = ...

Forward typedef declarations, effect on build times, and naming conventions

I am curious about the impact my typedef approach has on my builds. Please consider the following example. #include "SomeClass.h" class Foo { typedef SomeClass SomeOtherName; SomeOtherName* storedPointer; void setStoredPointer(SomeOtherName* s); } void Foo::setStoredPointer(SomeOtherName* s) { storedPointer = s; } ...

How to detect if errno_t is defined?

I'm compiling code using gcc that comes from Visual C++ 2008. The code is using errno_t, but in some versions of gcc headers including <errno.h> doesn't define the type. How do I detect if the type is defined? Is there a define that signals that the type was defined? In the case it isn't defined I'd like to provide the typedef to let the...

Typedef a template class without specifying the template parameters

I'm trying to typedef either an unordered_map or std::map depending whether there are TR1 libraries available. But I don't want to specify the template parameters. From what i've read so far, typedef'ing templates without arguments is not possible until official c++0x standard is available. So does anyone know an elegant workaround for t...

typedefs of structs not seeming to go through in header files?

I'm having some trouble with some struct typedef declarations in a header file not seeming to go through to my implementation file. Specifically, I have the following types defined: Type, Value, Integer, String, and Float. They are all typedef'd from struct names, in the exact same manner. I'm writing an informal hashCode function to su...

C typedef of pointer to structure

I had come across the following code: typedef struct { double x; double y; double z; } *vector Is this a valid type definition? The code compiles and runs fine. I was just curious if this is common practice. ...

Creating a new primitive type

Is there a way to create a new type that is like one of the basic types (eg char), and can be implcitly converted between, but will resolve diffrently in templates, such that for example, the following code works? typedef char utf8; template<typename T>void f(T c); template<> void f<char>(char c) { std::cout << "ascii " << c << std:...

#typedef and KVC in ObjC

I have a class that looks like this: @interface Properties : NSObject { @private NSNumber* prop1; NSNumberBool* prop2; //etc where NSNumberBool is a typedef: // in MyApp_Prefix.pch typedef NSNumber NSNumberBool; I have all the required @property and @synthesize declarations to make prop1 and prop2 properties. Everythin...

What does typedef do in C++.

typedef set<int, less<int> > SetInt; Please explain what this code does. ...

Understanding typedefs for function pointers in C: Examples, hints and tips, please.

I have always been a bit stumped when I read other peoples' code which had typedefs for pointers to functions with arguments. I recall that it took me a while to get around to such a definition while trying to understand a numerical algorithm written in C a while ago. So, could you share your tips and thoughts on how to write good typede...

Recommended approach to typedefs for standard types in C?

What's the recommended approach to typedefs for standard types in C? For example at the start of my project I created typedefs to use the smallest types possible for their purpose. The main intention was to allow for easy modification of the types in the case where the numerical ranges used became too large for the type without having t...

Objective-C use typedef enum to set Class behavior, like Cocoa.

Hi Im extending the UIButton Class to be able to set the font and color of the UINavigationBarButton ( from this code example: switch on the code ) I goes like this: @interface NavBarButtonGrey : UIButton -(id)init; @end @implementation NavBarButtonGrey -(id)init { if(self = [super init]) { self.frame = CGRectMake(0, 0, 49.0,...

typedef in template base class

I'm trying to define base class, which contains typedef's only. template<typename T> class A { public: typedef std::vector<T> Vec_t; }; template<typename T> class B : public A<T> { private: Vec_t v; // fails - Vec_t is not recognized }; Why in B I receive an error that Vec_t is not recognized and I need to write it explici...

typedef in c and type equivalence

If I do this: typedef int x[10]; x a; Is it same as: int a[10]; ? ...

C++ typedef question...easy one..

let's say I have: set<int, less<int> > m_intset; that works, but now I change it to typedef, and if I do I end up with two lines of code, right? typedef set<int, less<int> > SetInt; SetInt m_intset; So, what's the use? Is that the way to change it and use it? ...

Is typedef and #define the same in c?

I wonder if typedef and #define the same in c? ...

Is There C Syntax For Function Pointer From Function Declaration

Instead of declaring a function pointer typedef for a function, is it possible to get it from the function declaration? Typically, int foo(int x); typedef int (*fooFunc)(int); fooFunc aFunc; What I want: int foo(int x); foo* aFunc; I want to use it for dlsym: foo* aFunc; aFunc = dlsym(lib, "foo"); aFunc(x); If I update foo and ...

What is wrong with this c++ typedef?

This is a piece of my code, I have more class like MathStudent, ArtStudent, etc. which inherits Student class. When I tried to compile, it says "forbids declaration of `vector' with no type," what is the problem here? thanks class Student { public: typedef vector<Student> Friends; // something wrong here? virtual unsigned int ...

uint8_t vs unsigned char

What is the advantage of using uint8_t over unsigned char in C? I know that on almost every system uint8_t is just a typedef for unsigned char, so why use it? ...