typedef

Objective C - when should "typedef" precede "enum", and when should an enum be named?

In sample code, I have seen this: typedef enum Ename { Bob, Mary, John} EmployeeName; and this: typedef enum {Bob, Mary, John} EmployeeName; and this: typedef enum {Bob, Mary, John}; but what compiled successfully for me was this: enum {Bob, Mary, John}; I put that line in a .h file above the @interface line, and then when I ...

Why is the Objective-C Boolean data type defined as a signed char?

Something that has piqued my interest is Objective-C's BOOL type definition. Why is it defined as a signed char (which could cause unexpected behaviour if a value greater than 1 byte in length is assigned to it) rather than as an int, as C does (much less margin for error: a zero value is false, a non-zero value is true)? The only re...

Grammar and syntax of typedef in C language.

Hi folks: I have a problem with the typedef keywords in C language. In my program, I use the following codes: typedef int* a[10]; int main(){ int a[10]; } they work well. But why there are no conflicts between a variable and a type sharing the same name a? Regards. ...

Obj-C Error: Expected expression before ...... (why?)

Hi I have an enum declared like this: typedef enum { Top, Bottom, Center } UIItemAlignment; In my code I try to use it like this: item.alignment = UIItemAlignment.Top; I get an error like this: " Expected expression before 'UIItemAlignment' " If I use only: item.alignment = Top; everything works fine bu...

Enum "copy" problem

Hi all! I have a class, let's call it A. It has a enum (E) and a method Foo(E e), with gets E in the arguments. I want to write a wrapper (decorator) W for A. So it'll have its own method Foo(A::E). But I want to have some kind of encapsulation, so this method should defined as Foo(F f), where F is another enum defined in W, that can be ...

Why should structure names have a typedef?

I have seen source codes always having a typedef for a structure and using the same everywhere instead of using the structure name as "struct sname" etc directly? What is the reason behind this? Are there any advantages in doing this? ...

Coordinating typedefs and structs in std::multiset (C++)

I'm not a professional programmer, so please don't hesitate to state the obvious. My goal is to use a std::multiset container (typedef EventMultiSet) called currentEvents to organize a list of structs, of type Event, and to have members of class Host occasionally add new Event structs to currentEvents. The structs are supposed to be sor...

Define integer ranges in C

Hi, I want to define a type named Int_1_100_Type which is an integer variable in the range from 1 to 100. How should i typedef this one? for eg: i am passing this variable to a function which accepts variable of type Int_1_100_Type. i.e funca(Int_1_100_Type Var1) Thanks Maddy ...

typedef declaration syntax

Some days ago I looked at boost sources and found interesting typedef. There is a code from "boost\detail\none_t.hpp": namespace boost { namespace detail { struct none_helper{}; typedef int none_helper::*none_t ; } // namespace detail } // namespace boost I didn't see syntax like that earlier and can't explain the sense of that....

In C++, how can I make typedefs visible to every file in my project?

I have a typedef typedef unsigned int my_type; used in a file. I would like to make it visible across all my files, without putting it in a header file included by everything. I don't want to go the header file route because as it stands this will be the only declaration in the header file (and it seems unnecessary to add a file just...

Namespaces vs. Header files

Hi, I'm asking about the best practice widely used in C++ projects. I need to have my own types in the project. It's a collection of couple of typedefs. Is including header file containing the types good practice in C++ or is it better to use namespaces. If so, why? What are the pros and cons of the two ways? Right now it looks like ...

How to make a struct maker like CGRectMake (iphone)

i have a struct HLRange with two CGFloat's struct HOLRange { CGFloat min; CGFloat max; }; typedef struct HOLRange HOLRange; but how do i make a function like HLRangeMake(1,2); .. like CGRectMake? --EDIT-- my header file #import <Foundation/Foundation.h> struct HOLRange { CGFloat min; CGFloat max; }; typedef struct HOLRange...

assignment from incompatible pointer type

I have set up the following struct: typedef struct _thread_node_t { pthread_t thread; struct thread_node_t *next; } thread_node_t; ... and then I have defined: // create thread to for incoming connection thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t)); pthread_create(&(thread_node->thread), NULL, c...

How to check if the internal typedef struct of a typedef struct is NULL ?

typedef struct { uint32 item1; uint32 item2; uint32 item3; uint32 item4; <some_other_typedef struct> *table; } Inner_t; typedef struct { Inner_t tableA; Inner_t tableB; } Outer_t; Outer_t outer_instance = { {NULL}, { 0, 1, 2, 3, table_defined_somewhere_else, } }; My question i...

GDB doesnt like my typedef

It seems that the following is to deep for the debugger in Qt even though the program uses it without problem typedef QMap <int, QStringList> day2FileNameType; typedef QMap <int, day2FileNameType> month2day2FileNameType; typedef QMap <int, month2day2FileNameType> year2month2day2FileNameType; year2month2day2FileNameType y2m2d2f; now t...

Typedef C++, couldn't resolve its meaning

I read this typedef line in a C++ book, but I couldn't resolve its meaning: typedef Shape* (*CreateShapeCallBack)(); Now, CreateShapeCallBack stands for what, any idea? Thanks. ...

Alias for a C++ template?

typedef boost::interprocess::managed_shared_memory::segment_manager segment_manager_t; // Works fine, segment_manager is a class typedef boost::interprocess::adaptive_pool allocator_t; // Can't do this, adaptive_pool is a template The idea is that if I want to switch between boost interprocess' several different options for sh...

How to extract ALL typedefs and structs and unions from c++ source

I have inherited a Visual Studio project that contains hundreds of files. I would like to extract all the typedefs, structs and unions from each .h/.cpp file and put the results in a file). Each typdef/struct/union should be on one line in the results file. This would make sorting much easier. typdef int myType; struct myFirstStruc...

Proper use of of typedef in C++

I have coworkers who occasionally use typedef to avoid typing. For example: typedef std::list<Foobar> FoobarList; ... FoobarList GetFoobars(); Personally, I always hate coming across code like this, largely because it forces me to go lookup the typedef so I can tell how to use it. I also feel like this sort of thing is a potential sli...

What is the difference between declaring an enum with and without 'typedef'?

The standard way of declaring an enum in C++ seems to be: enum <identifier> { <list_of_elements> }; However, I have already seen some declarations like: typedef enum { <list_of_elements> } <identifier>; What is the difference between them, if it exists? Which one is correct? ...