Search Results

Search found 976 results on 40 pages for 'typedef'.

Page 22/40 | < Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >

  • [C] converting Bit Field to int

    - by shaharg
    Hi, I have bit field declared this way: typedef struct morder { unsigned int targetRegister : 3; unsigned int targetMethodOfAddressing : 3; unsigned int originRegister : 3; unsigned int originMethodOfAddressing : 3; unsigned int oCode : 4; } bitset; I also have int array, and i want to get int value from this array, that represents the actual value of this bit field (which is actually some kind of machine word that i have the parts of it, and i want the int representation of the whole word). Thanks a lot.

    Read the article

  • Interop Structure: Should Unsigned Short be Mapped to byte[]?

    - by Ngu Soon Hui
    I have such a C++ structure: typedef struct _FILE_OP_BLOCK { unsigned short fid; // objective file ID unsigned short offset; // operating offset unsigned char len; // buffer length(update) // read length(read) unsigned char buff[MAX_BUFF_SIZE]; } FILE_OP_BLOCK; And now I want to map it in .Net. The tricky thing is that the I should pass a 2 byte array for fid, and integer for len, even though in C# fid is an unsigned short and len is an unsigned char I wonder whether my structure ( in C#) below is correct? public struct File_OP_Block { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] fid; public ushort offset; public byte length; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 240)] public char[] buff; }

    Read the article

  • How to invoke an Objective-C Block via the LLVM C++ API?

    - by smokris
    Say, for example, I have an Objective-C compiled Module that contains something like the following: typedef bool (^BoolBlock)(void); BoolBlock returnABlock(void) { return Block_copy(^bool(void){ printf("Block executing.\n"); return YES; }); } ...then, using the LLVM C++ API, I load that Module and create a CallInst to call the returnABlock() function: Function *returnABlockFunction = returnABlockModule->getFunction(std::string("returnABlock")); CallInst *returnABlockCall = CallInst::Create(returnABlockFunction, "returnABlockCall", entryBlock); How can I then invoke the Block returned via the returnABlockCall object?

    Read the article

  • structures, inheritance and definition

    - by Meloun
    Hi, i need to help with structures, inheritance and definition. //define struct struct tStruct1{ int a; }; //definition tStruct1 struct1{1}; and inheritance struct tStruct2:tStruct1{ int b; }; How can I define it in declaration line? tStruct2 struct2{ ????? }; One more question, how can i use inheritance for structures defined with typedef struct?

    Read the article

  • Glib hash table replace

    - by Robert
    I'm using GLib Hash Table. I'm trying to get the current value of the key that I found and then increment its value. I'm not quite sure how can I replace the existing value. typedef struct { gchar *key; guint my_int; } my_struct; char *v; v = g_hash_table_lookup(table, my_struct.key); if (v == NULL) g_hash_table_insert(table, g_strdup(my_struct.key), (gpointer)(my_struct.my_int)); else g_hash_table_replace() // here I'd like to do something like current_val+1 Any ideas will be appreciate it.

    Read the article

  • passing structure directly to function

    - by ra170
    I have a struct that I initialize like this: typedef struct { word w; long v; } MyStruct; MyStruct sx = {0,0}; Update(sx); Now, it seems such a waste to first declare it and then to pass it. I know that in C#, there's a way to do everything in one line. Is there any possiblity of passing it in a more clever (read: cleaner) way to my update function?

    Read the article

  • Why does this give a segmentation fault?

    - by nightcracker
    I'm stunned, why does this code give me a segmentation fault? #include <stdio.h> #define LIMIT 1500000 typedef struct { int p; int a; int b; } triplet; int main(int argc, char **argv) { int i; triplet triplets[LIMIT]; for (i = 0; i < 5; i++) { triplets[i].p = 9; // remove this line and everything works fine } printf("%d\n", triplets[15].p); return 0; } EDIT: After changing LIMIT to 150 I no longer get a segmentation fault, it prints random numbers instead.

    Read the article

  • Write pointer to file in C

    - by Sergey
    I have a stucture: typedef structure student { char *name; char *surname; int age; } Student; I need to write it to binary file. Student *s = malloc(sizeof(*s)); I fill my structure with data and then i write in to the file: fwrite(s, sizeof(*s), 1, fp); In my file doesnt exist a name and surname, it have an adresses of char*. How can i write to file a word, not an adresses?

    Read the article

  • C++ Class Static variable problem - C programmer new to C++

    - by Microkernel
    Hi guys, I am a C programmer, but had learnt C++ @school longtime back. Now I am trying to write code in C++ but getting compiler error. Please check and tell me whats wrong with my code. typedef class _filter_session { private: static int session_count; /* Number of sessions count -- Static */ public: _filter_session(); /* Constructor */ ~_filter_session(); /* Destructor */ }FILTER_SESSION; _filter_session::_filter_session(void) { (this->session_count)++; return; } _filter_session::~_filter_session(void) { (this->session_count)--; return; } The error that I am getting is "error LNK2001: unresolved external symbol "private: static int _filter_session::session_count" (?session_count@_filter_session@@0HA)" I am using Visual Studio 2005 by the way. Plz plz help me. Regards, Microkernel

    Read the article

  • Looking for a good explanation of the table generation macro idiom

    - by detly
    I want to make this clear up front : I know how this trick works, what I want is a link to a clear explanation to share with others. One of the answers to a C macro question talks about the "X macro" or "not yet defined macro" idiom. This involves defining something like: #define MAGIC_LIST \ X(name_1, default_1) \ X(name_2, default_2) \ ... Then to create, say, an array of values with named indices you do: typedef enum { #define X(name, val) name, MAGIC_LIST #undef X } NamedDefaults; You can repeat the procedure with a different #define for X() to create an array of values, and maybe debugging strings, etc. I'd like a link to a clear explanation of how this works, pitched at someone who is passably familiar with C. I have no idea what everyone usually calls this pattern, though, so my attempts to search the web for it have failed thus far. (If there is such an explanation on SO, that'd be fine...)

    Read the article

  • Objective-C / C giving enums default values

    - by bandejapaisa
    I read somewhere about giving enums default values like so: typedef enum { MarketNavigationTypeNone = 0, MarketNavigationTypeHeirachy = 1, MarketNavigationTypeMarket = 2 } MarketNavigationLevelType; .. but i can't remember the value of doing this. If i don't give them default values - and then someone later on reorders the enum - what are the risks? If i always use the enum name and don't even refer to them by their integer value, is there any risks? The only possible problem i can think of is if i'm initialising an enum from an int value from a DB - and the enum is reordered - then the app would break.

    Read the article

  • C++ MTL Library dimension.h bug?

    - by avanwieringen
    I've installed MTL on my Fedora Core 12 x64 system, but when building an application I get the following error: In file included from /usr/local/include/mtl/matrix.h:41, from /usr/local/include/mtl/mtl.h:40, from ltiSystem.hxx:4, from strTools.hxx:4, from ff.cxx:3: /usr/local/include/mtl/envelope2D.h:72: error: declaration of ‘typedef struct mtl::twod_tag mtl::envelope2D<T>::dimension’ /usr/local/include/mtl/dimension.h:19: error: changes meaning of ‘dimension’ from ‘class mtl::dimension<typename mtl::dense1D<T, 0>::size_type, 0, 0>’ make[1]: *** [ff.o] Error 1 Which would imply an error in MTL. I have changed to different MTL versions and the problem persists, but on Google there is no proper answer. I use the g++ compiler. Does anyone have a clye?

    Read the article

  • Does malloc() allocate a contiguous block of memory?

    - by user66854
    I have a piece of code written by a very old school programmer :-) . it goes something like this typedef struct ts_request { ts_request_buffer_header_def header; char package[1]; } ts_request_def; ts_request_buffer_def* request_buffer = malloc(sizeof(ts_request_def) + (2 * 1024 * 1024)); the programmer basically is working on a buffer overflow concept. I know the code looks dodgy. so my questions are: Does malloc always allocate contiguous block of memory ?. because in this code if the blocks are not contiguous , the code will fail big time Doing free(request_buffer) , will it free all the bytes allocated by malloc i.e sizeof(ts_request_def) + (2 * 1024 * 1024), or only the bytes of the size of the structure sizeof(ts_request_def) Do you see any evident problems with this approach , i need to discuss this with my boss and would like to point out any loopholes with this approach

    Read the article

  • error handling strategies in C?

    - by Leo
    Given the code below: typedef struct {int a;} test_t; arbitrary_t test_dosomething(test_t* test) { if (test == NULL) { //options: //1. print an error and let it crash //e.g. fprintf(stderr, "null ref at %s:%u", __FILE__, __LINE__); //2. stop the world //e.g. exit(1); //3. return (i.e. function does nothing) //4. attempt to re-init test } printf("%d", test->a); //do something w/ test } I want to get a compiler error if test is ever NULL, but I guess that's not possible in C. Since I need to do null checking at runtime, what option is the most proper way to handle it?

    Read the article

  • Conditional type definitions

    - by pythonic metaphor
    I'm sure that boost has some functions for doing this, but I don't know the relevant libraries well enough. I have a template class, which is pretty basic, except for one twist where I need to define a conditional type. Here is the psuedo code for what I want struct PlaceHolder {}; template <typename T> class C{ typedef (T == PlaceHolder ? void : T) usefulType; }; How do I write that type conditional?

    Read the article

  • use callback function to report stack backtrace

    - by user353394
    Assume I have the following: typedef struct { char *name; char binding; int address; } Fn_Symbol //definition of function symbol static Fn_Symbol *fnSymbols; //array of function symbols in a file statc int total; //number of symbol functions in the array and file static void PrintBacktrace(int sigum, siginfo_t * siginfo, void *context) { printf("\nSignal received %d (%s)\n", signum, strsignal(signum)); const int eip_index = 14; void *eip = (void *)((struct ucontext *)context)->uc_mcontext.gregs[eip_index]; printf("Error at [%p] %s (+0x%x), eip, fnName, offset from start); //????? exit(0); } I have this so far, but what is the best way using the fnSymbols static global pointer to identify the function where the error occured and then back trace through the stack to identify each calling function by address, name, and offset?

    Read the article

  • how to callback a lua function from a c function

    - by pierr
    Hi, I have a c function test_callback accepting a point to a function as the parameter and It will "callback" that function. //typedef int(*data_callback_t)(int i); int test_callback(data_callback_t f) { f(3); } int datacallback(int a ) { printf("called back %d\n",a); return 0; } //example test_callback(datacallback); // print : called back 3 Now, I want to wrap test_callback so that they can be called from lua, suppose the name is lua_test_callback ;and also the input parameter to it would be a lua function. How should I achieve this goal? function lua_datacallback (a ) print "hey , this is callback in lua" ..a end lua_test_callback(lua_datacallback) //expect to get "hey this is callback in lua 3 "

    Read the article

  • Double indirection and structures passed into a function

    - by ZPS
    I am curious why this code works: typedef struct test_struct { int id; } test_struct; void test_func(test_struct ** my_struct) { test_struct my_test_struct; my_test_struct.id=267; *my_struct = &my_test_struct; } int main () { test_struct * main_struct; test_func(&main_struct); printf("%d\n",main_struct->id); } This works, but pointing to the memory address of a functions local variable is a big no-no, right? But if i used a structure pointer and malloc, that would be the correct way, right? void test_func(test_struct ** my_struct) { test_struct *my_test_struct; my_test_struct = malloc(sizeof(test_struct)); my_test_struct->id=267; *my_struct = my_test_struct; } int main () { test_struct * main_struct; test_func(&main_struct); printf("%d\n",main_struct->id); }

    Read the article

  • JNI: dll function works ok in C++ main, but not with dll wrapper

    - by Joseph Lim
    I have an a.dll (not modifiable as i do not have the source) with a function bool openPort(DWORD mem).I wrote a c++ main, loaded this dll using LoadLibrary, and the function works well.It returns true. Now, I need to call this function from Java via JNI. I wrote another b.dll with a function like so JNIEXPORT void JNICALL Java_MyClass_openPortFunc (JNIEnv *env, jobject obj, jint pMemPhy) { hInstLibrary = LoadLibrary("a.dll"); typedef bool (*openPort)(DWORD); openPort _openPort; _openPort = (openPort)GetProcAddress(hInstLibrary, "openPort"); DWORD memAddr = 0xda000; if(_openPort(memAddr)){ cout << "ok" << endl; }else{ cout << "failed " << endl; } } This however, causes the openPort to return false despite using the same parameters. I hope someone can advise me. Thank you. :)

    Read the article

  • Printing the address of a struct object

    - by bdhar
    I have a struct like this typedef struct _somestruct { int a; int b; }SOMESTRUCT,*LPSOMESTRUCT; I am creating an object for the struct and trying to print it's address like this int main() { LPSOMESTRUCT val = (LPSOMESTRUCT)malloc(sizeof(SOMESTRUCT)); printf("0%x\n", val); return 0; } ..and I get this warning warning C4313: 'printf' : '%x' in format string conflicts with argument 1 of type 'LPSOMESTRUCT' So, I tried to cast the address to int like this printf("0%x\n", static_cast<int>(val)); But I get this error: error C2440: 'static_cast' : cannot convert from 'LPSOMESTRUCT' to 'int' What am I missing here? How to avoid this warning? Thanks.

    Read the article

  • How to sanely read and dump structs to disk when some fields are pointers?

    - by bp
    Hello, I'm writing a FUSE plugin in C. I'm keeping track of data structures in the filesystem through structs like: typedef struct { block_number_t inode; filename_t filename; //char[SOME_SIZE] some_other_field_t other_field; } fs_directory_table_item_t; Obviously, I have to read (write) these structs from (to) disk at some point. I could treat the struct as a sequence of bytes and do something like this: read(disk_fd, directory_table_item, sizeof(fs_directory_table_item_t)); ...except that cannot possibly work as filename is actually a pointer to the char array. I'd really like to avoid having to write code like: read(disk_df, *directory_table_item.inode, sizeof(block_number_t)); read(disk_df, directory_table_item.filename, sizeof(filename_t)); read(disk_df, *directory_table_item.other_field, sizeof(some_other_field_t)); ...for each struct in the code, because I'd have to replicate code and changes in no less than three different places (definition, reading, writing). Any DRYer but still maintainable ideas?

    Read the article

  • [SOLVED]Port C's fread(&struct,....) to Python

    - by user287669
    Hey, I'm really struggling with this one. I'am trying to port a small piece of someone else's code to Python and this is what I have: typedef struct { uint8_t Y[LUMA_HEIGHT][LUMA_WIDTH]; uint8_t Cb[CHROMA_HEIGHT][CHROMA_WIDTH]; uint8_t Cr[CHROMA_HEIGHT][CHROMA_WIDTH]; } __attribute__((__packed__)) frame_t; frame_t frame; while (! feof(stdin)) { fread(&frame, 1, sizeof(frame), stdin); // DO SOME STUFF } Later I need to access the data like so: frame.Y[x][y] So I made a Class 'frame' in Python and inserted the corresponding variables(frame.Y, frame.Cb, frame.Cr). I have tried to sequentially map the data from Y[0][0] to Cr[MAX][MAX], even printed out the C struct in action but didn't manage to wrap my head around the method used to put the data in there. I've been struggling overnight with this and have to get back to the army tonight, so any immediate help is very welcome and appreciated. Thanks

    Read the article

  • status failed for LdrLoadDll

    - by kiddo
    hello all,I'am trying to work-out the LdrLoadDll function and am having no luck with that..i also googled for some examples there is no much documentation or correct example about this.I know what it exactly does..Please check the code below. //declaration function pointer for LdrLoadDll typedef NTSTATUS (_stdcall*fp_LdrLoadDll)( IN PWCHAR PathToFile OPTIONAL, IN ULONG Flags OPTIONAL, IN PUNICODE_STRING ModuleFileName, OUT PHANDLE ModuleHandle ); //calling LdrLoadDll using getprocaddress HANDLE handle; HMODULE module = LoadLibrary(L"ntdll.dll"); fp_LdrLoadDll loadDll; loadDll = (fp_LdrLoadDll)GetProcAddress(module,"LdrLoadDll"); if(loadDll == NULL) { MessageBox(0,L"Not able to load the function",L"LdrLoadDll",&handle); } UNICODE_STRING input; input.Buffer = L"C:\\Desktop\\myDll.dll"; input.Length = wcslen(input.Buffer)*2; input.MaximumLength = wcslen(input.Buffer) +2; NTSTATUS status = loadDll(NULL,LOAD_WITH_ALTERED_SEARCH_PATH,&input,0); When i execute the above am not getting the handle niether valid status.Please help me with this.

    Read the article

  • Why freed struct in C still has data?

    - by kliketa
    When I run this code: #include <stdio.h> typedef struct _Food { char name [128]; } Food; int main (int argc, char **argv) { Food *food; food = (Food*) malloc (sizeof (Food)); snprintf (food->name, 128, "%s", "Corn"); free (food); printf ("%d\n", sizeof *food); printf ("%s\n", food->name); } I still get 128 Corn although I have freed food. Why is this? Is memory really freed?

    Read the article

  • How do I pass (by value) a struct in Objective-C?

    - by Striker
    This one has been driving me mad! I have a struct: typedef struct{ int a; }myStruct; Then I have: myStruct tempStruct; I am trying to pass the struct to a class method whose implementation is: - (void) myFunc:(struct myStruct)oneOfMyStructs{}; I call the method like so: [myClass myFunc:(struct myStruct)tempStruct]; The compiler complains about "Conversion to non-scalar type requested." All I want to do is pass a struct into a class method, but the syntax has me a bit confused. I'm new to Objective-C. Please let me know if you can see where I'm going wrong. I've not been able to pass by reference either, so if you could help me out with that, that would be great! Thanks!

    Read the article

< Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >