Search Results

Search found 2566 results on 103 pages for 'struct'.

Page 8/103 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Casting to global variable from LPVOID - C

    - by Jamie Keeling
    I am trying to cast data to a struct from a parameter passed into my method, I need the data to be passed to a global variable as it is needed elsewhere in my application. I have tried the following but I get errors saying that diceResult is an undeclared identifier Here is the code itself: //Structure to hold dice data typedef struct diceData { int dice1; int dice2; }; struct diceResult; DWORD WINAPI UnpackDiceData(LPVOID sentData) { //Unpack data struct diceData unpackedData = *((struct diceData*)sentData); diceResult.dice1 = unpackedData.dice1; diceResult.dice2 = unpackedData.dice2; } I don't understand why it won't recognise it being there when it's clearly global.

    Read the article

  • Multiple Linked List in C

    - by LuckySlevin
    I have a problem about Linked Lists. I already know how to create structures and linked list. But now I have to create arbitrary number of linked list which are also be kept in another structure. Which means : struct list{int x, struct list *next; }; struct parent{int x, struct list *head, struct parent *next;} And after lists are created when i enter this input for example "123134 linked list should look like : 1 - 2 - 3 - 4 And for example 1 will contain 2-3 list inside of it, 3 will contain 1-4 list inside of it. I need a starting point and a spark from you. So how can i do this?

    Read the article

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

    - by Michael Wells
    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 myFirstStruct { char a; int b;...}; union Part_Number_Serial_Number_Part_2_Response_Message_Type {struct{Message_Response_Head_Type Head; Part_Num_Serial_Num_Part_2_Report_Array Part_2_Report; Message_Tail_Type Tail;} Data; BYTE byData[140];}myUnion; struct { bool c; int d;...}mySecondStruct; My problem is, I do not know what to look for (grammar of typedef/structs/unions) using a regular expression. I cannot believe that nobody has done this before (I googled and have not found anything on this). Does anyone know the regular expressions for these? (Note some are commented out using // others /* */) Or a tool to accomplish this. Edit: I am toying with the idea of autogenerating source code and/or dialogs for modifying messages that use the underlying typedef/struct/union. I was going to use the output to generate an XML file that could be used for this reason. The source for these are in C/C++ and used in almost all my projects. These projects are usually NOT in C/C++. By using the XML version I would only need to update/add the typedef/struct/union only in one place and all the projects would be able to autogen the source and/or dialogs.

    Read the article

  • Why can't my vector access the variables in my nested structs?

    - by chucknorris
    #include<iostream> #include<vector> #include<string> #include<list> using namespace std; struct record{ int id; string fName; }; struct cells{ list<record> rec; }; vector<cells> hp; int main() { **hp.front().rec.front().fName = "jon"; return 0; } I have 2 structs. The first struct, struct record, is composed of 2 regular variables. In struct 2, I have a linked list of type "record", which includes all the variable listed in struct 1. Why is it that when ever I attempt to access a variable in the structs, using my vector, I get the error "linked list iterator not dereferencable?"

    Read the article

  • How can I have a serializable struct that wraps it's self as an int32 implicitly? in C#?

    - by firoso
    Long story short, I have a struct (see below) that contains exactly one field: private int value; I've also implemented implicit conversion operators: public static implicit operator int(Outlet val) { return val.value; } public static implicit operator Outlet(int val) { return new Outlet(val); } I've implemented all of the following : IComparable, IComparable<Cart>, IComparable<int>, IConvertible, IEquatable<Cart>, IEquatable<int>, IFormattable I'm at a point where I really have no clue why, but whenever I serialize this object, I get no value. For instance, with XmlSerialization: <Outlet /> Also, I'm not solely concerned about XmlSerialization, I'm concerned about ALL serialization (binary for instance) How can I ensure that this serializes properly? NOTE: I did this because mapping an int,int dictionary seemed rather poorly typed to me when explicit objects with validation behavior were desired.

    Read the article

  • Populate struct values with function argument

    - by adohertyd
    I am working on a program and part of it requires me to create a struct called DETAILS with the fields name, age, and height. I want to populate the record with data using a function argument. When I run my code I get compiler errors. I have put the errors in comment form beside the lines it is returned for but I can't fix them. Really could do with some help here guys thanks so much. Here is my code: #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; const int LEN=100; struct DETAILS { char name[LEN]; int age; double height; }; person fillperson(struct DETAILS, char[LEN], int, double); int main() { struct person David; fillperson(David, "David Greene", 38, 180.0); //deprecated conversion from string constant to char * [-Wwrite-Strings] } person fillperson(struct DETAILS, char[LEN] name, int age, double height) //expected , or ... before 'name' { cin>>David.name>>name; cin>>David.age>>age; cin>>David.height>>height; cout<<"Done"<<endl; }

    Read the article

  • Add static const data to a struct already defined

    - by Kyle
    Since static const data inside a class is really just namespace sugar for constants I would think that struct A { float a; struct B { static const int b = a; }; }; would be equivalent to struct A { float a; }; struct A::B { static const int b = a; }; or something similar. Is something like this possible in C++? It would be useful for me to be able to tag class definitions that I'm pulling in from third party libraries with information like this.

    Read the article

  • Question on struct

    - by barbgal
    i see lot of struct code like below struct codDrives { WCHAR letter; WCHAR volume[100]; } Drives[26]; we can use variables or array something like that to store the data.. but i am not sure why use struct in the programs. i am beginner so please for my dump question Thank you for the time spent to me

    Read the article

  • Pinvoke- to call a function with pointer to pointer to pointer parameter

    - by jambodev
    complete newbe in PInvoke. I have a function in C with this signature: int addPos(int init_array_size, int *cnt, int *array_size, PosT ***posArray, PosT ***hPtr, char *id, char *record_id, int num, char *code, char *type, char *name, char *method, char *cont1, char *cont2, char *cont_type, char *date1, char *date_day, char *date2, char *dsp, char *curr, char *contra_acc, char *np, char *ten, char *dsp2, char *covered, char *cont_subtype, char *Xcode, double strike, int version, double t_price, double long, double short, double scale, double exrcised_price, char *infoMsg); and here is how PosT looks like: typedef union pu { struct dpos d; struct epo e; struct bpos b; struct spos c; } PosT ; my questions are: 1- do I need to define a class in CSharp representing PosT? 2- how do I pass PosT ***posArray parameter across frm CSharp to C? 3- How do I specify marshaling for it all? I Do appreciate your help

    Read the article

  • C++ min heap with user-defined type.

    - by bsg
    Hi, I am trying to implement a min heap in c++ for a struct type that I created. I created a vector of the type, but it crashed when I used make_heap on it, which is understandable because it doesn't know how to compare the items in the heap. How do I create a min-heap (that is, the top element is always the smallest one in the heap) for a struct type? The struct is below: struct DOC{ int docid; double rank; }; I want to compare the DOC structures using the rank member. How would I do this? I tried using a priority queue with a comparator class, but that also crashed, and it also seems silly to use a data structure which uses a heap as its underlying basis when what I really need is a heap anyway. Thank you very much, bsg

    Read the article

  • MPI and C structs

    - by hanno
    I have to admit, I was quite shocked to see how many lines of code are required to transfer one C struct with MPI. Under what circumstances will it work to simply transmit a struct using the predefined dataype MPI_CHAR? Consider the following example: struct particle { double x; double y; long i; }; struct particle p; MPI_Isend(&p, sizeof(particle), MPI_CHAR, tag, MPI_COMM_WORLD, &sendr); In my case, all processes run on the same architecture. Is padding the only issue?

    Read the article

  • C programming: Dereferencing pointer to incomplete type error

    - by confusedKid
    Hi, I am pretty rusty at C, and I'm getting a dereferencing error. Hopefully someone can help me with this? ^_^ I have a struct defined as: struct { char name[32]; int size; int start; int popularity; } stasher_file; and an array of pointers to those structs: struct stasher_file *files[TOTAL_STORAGE_SIZE]; In my code, I'm making a pointer to the struct and setting its members, and adding it to the array: ... struct stasher_file *newFile; strncpy(newFile-name, name, 32); newFile-size = size; newFile-start = first_free; newFile-popularity = 0; files[num_files] = newFile; ... I'm getting a "error: dereferencing pointer to incomplete type" whenever I try to access the members inside newFile. What am I doing wrong? Thanks very much for any help :)

    Read the article

  • Array of templated structs

    - by Jakub Mertlik
    I have structs templated by int derived from a Base struct. struct Base { int i; double d; }; template< int N > struct Derv : base { static const int mN = N; }; I need to make an array of Derv< N where N can vary for each struct in that array. I know C/C++ does not allow arrays of objects of different types, but is there a way around this? I was thinking of separating the type information somehow (hints like pointers to Base struct or usage of union spring to my mind, but with all of these I don't know how to store the type information of each array element for usage DURING COMPILE TIME). As you can see, the memory pattern of each Derv< N is the same. I need to access the type of each array element for template specialization later in my code. The general aim of this all is to have a compile-time dispatch mechanism without the need to do a runtime "type switch" somewhere in the code. Thank you.

    Read the article

  • Clone existing structs with different alignment in Visual C++

    - by Crend King
    Is there a way to clone an existing struct with different member alignment in Visual C++? Here is the background: I use an 3rd-party library, which uses several structs. To fill up the structs, I pass the address of the struct instances to some functions. Unfortunately, the functions only returns unaligned buffer, so that data of some members are always wrong. /Zp is out of choice, since it breaks the other parts of the program. I know #pragma pack modifies the alignment of the following struct, but I would like to avoid copying the structs into my code, for the definitions in the library might change in the future. Sample code: test.h: struct am_aligned { BYTE data1[10]; ULONG data2; }; test.cpp: #include "test.h" // typedef alignment(1) struct am_aligned am_unaligned; int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { char buffer[20] = {}; for (int i = 0; i < sizeof(unaligned_struct); i++) { buffer[i] = i; } am_aligned instance = *(am_aligned*) buffer; return 0; } Consider am_aligned is defined in the library header file. am_unaligned is my custom declaration, and only effective in test.cpp. The commented line does not work of course. instance.data2 is 0x0f0e0d0c, while 0x0d0c0b0a is desired. Thanks for help!

    Read the article

  • displaying structs in an array using enumerator

    - by Mostaguen
    In an object I have : public IEnumerable<voiture> recup_voitures() { foreach (voiture v in _arrVCollection) { yield return (v); } } voiture being a struct and _arrVCollection being an array containing some struct voiture. In my main class I have : foreach (CarCollection.voiture o in collection.recup_voitures()) { //some code to display the content of each struct } What is happening is that if I have an array of length 5 and only 1 struct voiture in it, it will do the displaying code 5 times instead of only 1. What am I doing wrong?

    Read the article

  • Accessing any structs members at run-time.

    - by jmgunn
    Is it possible to get access to an individual member of a struct or class without knowing the names of its member variables? I would like to do an "offsetof(struct, tyname)" without having the struct name or member variable name hard coded amoungst other things. thanks.

    Read the article

  • Array of Structs Initialization....

    - by user69514
    Hi I am working on a program where I have to initialize a deck of cards. I am using a struct to represent a card. However I'm not filling it correctly as I get a bunch of zero's when I display the deck of cards. I believe my mistake is in this line but I'm not sure: struct card temp = {"Clubs", value, false}; The code: void initCards(){ int count = 0; int location = 0; const int hand = 12; //add hearts int value=2; while( count < hand ){ struct card temp = {"Hearts", value, false}; cards[location] = temp; value++; count++; } count = 0; //add diamonts value = 2; while( count < hand ){ struct card temp = {"Diamonds", value, false}; cards[count] = temp; value++; count++; } //add spades count = 0; value = 2; while( count < hand ){ struct card temp = {"Spades", value, false}; cards[count] = temp; value++; count++; } //add clubs count = 0; value = 2; while( count < hand ){ struct card temp = {"Clubs", value, false}; cards[count] = temp; value++; count++; } //print the deck for(int i=0; i<52; i++){ cout << cards[i].type << " " << cards[i].rank << endl; } }

    Read the article

  • size of structures in .NET

    - by redpaladin
    My problem is very simple. My problem is to send a structure between a program in C to a C# program. I made a struct in C#: public struct NetPoint { public float lat; // 4 bytes public float lon; // 4 bytes public int alt; // 4 bytes public long time; // 8 bytes } Total size of the struct must be 20 bytes. When I do a sizeof() of this struct: System.Diagnostics.Debug.WriteLine("SizeOf(NetPoint)=" + System.Runtime.InteropServices.Marshal.SizeOf(new NetPoint())); The debug console shows: SizeOf(NetPoint)=24 But I expected to have 20 bytes. Why do I see a difference?

    Read the article

  • writing structs and classes to disk

    - by Phenom
    The following function writes a struct to a file. int btwrite(short rrn, BTPAGE *page_ptr) { long addr; addr = (long) rrn * (long) PAGESIZE + HEADERSIZE; lseek(btfd, addr, 0); return (write(btfd, page_ptr, PAGESIZE)); } The following is the struct. typedef struct { short keycount; /* number of keys in page */ int key[MAXKEYS]; /* the actual keys */ int value[MAXKEYS]; /* the actual values */ short child[MAXKEYS+1]; /* ptrs to rrns of descendants */ } BTPAGE; What would happen if I changed the struct to a class, would it still work the same? If I added class functions, would the size it takes up on disk increase?

    Read the article

  • structure in .NET

    - by redpaladin
    My problem is very simple.. My problem is to send a structure beetween a program in C to a C# program.. I made a struct in C#: public struct NetPoint { public float lat; // 4 bytes public float lon; // 4 bytes public int alt; // 4 bytes public long time; // 8 bytes } Total size of the struct must be 20 bytes When i do a sizeof() of this struct System.Diagnostics.Debug.WriteLine("SizeOf(NetPoint)=" + System.Runtime.InteropServices.Marshal.SizeOf(new NetPoint())); The debug console show : SizeOf(NetPoint)=24 But i expected to have 20 bytes ? Why do I have a difference ? Thank you in advance

    Read the article

  • C# Strange Behavior

    - by Betamoo
    I have a custom struct : struct A { public int y; } a custom class with empty constuctor: class B { public A a; public B() { } } and here is the main: static void Main(string[] args) { B b = new B(); b.a.y = 5;//No runtime errors! Console.WriteLine(b.a.y); } When I run the above program, it does not give me any errors, although I did not initialize struct A in class B constructor..'a=new A();'

    Read the article

  • Read binary file into a struct C#

    - by Robert Höglund
    I'm trying to read binary data using C#. I have all information about the layout of the data in the files I want to read. I'm able to read the data "chunk by chunk", i.e. getting the first 40 bytes of data converting it to a string, get the next 40 bytes, ... Since there are at least three slighlty different version of the data, I would like to read the data directly into a struct. It just feels so much more right than by reading it "line by line". I have tried the following approach but to no avail:StructType aStruct; int count = Marshal.SizeOf(typeof(StructType)); byte[] readBuffer = new byte[count]; BinaryReader reader = new BinaryReader(stream); readBuffer = reader.ReadBytes(count); GCHandle handle = GCHandle.Alloc(readBuffer, GCHandleType.Pinned); aStruct = (StructType) Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(StructType)); handle.Free(); The stream is an opened FileStream from which I have began to read from. I get an AccessViolationException when using Marshal.PtrToStructure. The stream contains more information than I'm trying to read since I'm not interested in data at the end of the file. The struct is defined like:[StructLayout(LayoutKind.Explicit)] struct StructType { [FieldOffset(0)] public string FileDate; [FieldOffset(8)] public string FileTime; [FieldOffset(16)] public int Id1; [FieldOffset(20)] public string Id2; } The examples code is changed from original to make this question shorter. How would I read binary data from a file into a struct?

    Read the article

  • Marshalling a big-endian byte collection into a struct in order to pull out values

    - by Pat
    There is an insightful question about reading a C/C++ data structure in C# from a byte array, but I cannot get the code to work for my collection of big-endian (network byte order) bytes. (EDIT: Note that my real struct has more than just one field.) Is there a way to marshal the bytes into a big-endian version of the structure and then pull out the values in the endianness of the framework (that of the host, which is usually little-endian)? This should summarize what I'm looking for (LE=LittleEndian, BE=BigEndian): void Main() { var leBytes = new byte[] {1, 0}; var beBytes = new byte[] {0, 1}; Foo fooLe = ByteArrayToStructure<Foo>(leBytes); Foo fooBe = ByteArrayToStructureBigEndian<Foo>(beBytes); Assert.AreEqual(fooLe, fooBe); } [StructLayout(LayoutKind.Explicit, Size=2)] public struct Foo { [FieldOffset(0)] public ushort firstUshort; } T ByteArrayToStructure<T>(byte[] bytes) where T: struct { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),typeof(T)); handle.Free(); return stuff; } T ByteArrayToStructureBigEndian<T>(byte[] bytes) where T: struct { ??? }

    Read the article

  • Writing/Reading struct w/ dynamic array through pipe in C

    - by anrui
    I have a struct with a dynamic array inside of it: struct mystruct{ int count; int *arr; }mystruct_t; and I want to pass this struct down a pipe in C and around a ring of processes. When I alter the value of count in each process, it is changed correctly. My problem is with the dynamic array. I am allocating the array as such: mystruct_t x; x.arr = malloc( howManyItemsDoINeedToStore * sizeof( int ) ); Each process should read from the pipe, do something to that array, and then write it to another pipe. The ring is set up correctly; there's no problem there. My problem is that all of the processes, except the first one, are not getting a correct copy of the array. I initialize all of the values to, say, 10 in the first process; however, they all show up as 0 in the subsequent ones. for( j = 0; j < howManyItemsDoINeedToStore; j++ ){ x.arr[j] = 10; } Initally: 10 10 10 10 10 After Proc 1: 9 10 10 10 15 After Proc 2: 0 0 0 0 0 After Proc 3: 0 0 0 0 0 After Proc 4: 0 0 0 0 0 After Proc 5: 0 0 0 0 0 After Proc 1: 9 10 10 10 15 After Proc 2: 0 0 0 0 0 After Proc 3: 0 0 0 0 0 After Proc 4: 0 0 0 0 0 After Proc 5: 0 0 0 0 0 Now, if I alter my code to, say, struct mystruct{ int count; int arr[10]; }mystruct_t; everything is passed correctly down the pipe, no problem. I am using READ and WRITE, in C: write( STDOUT_FILENO, &x, sizeof( mystruct_t ) ); read( STDIN_FILENO, &x, sizeof( mystruct_t ) ); Any help would be appreciated. Thanks in advance!

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >