Все вопросы: [struct]

317 вопросов

6
голосов
3ответов
2337 просмотров

Objective C Structs and Memory Management

Simple question - do i need to free or release structs. My reason for asking is that I'm use a NSInvocation and the SEL type is a struct. Just want to know if I need to release it. Thanks.

11
голосов
5ответов
9474 просмотров

Does ColdFusion have a short syntax for creating a struct?

Is there any "short" syntax for creating a struct in ColdFusion? I'd like to replace this verbose code: <cfscript> ref = StructNew(); ref.Template = "Label"; ref.Language = "en"; stcML = GetPrompts(ref); </cfscript> with something more like a JavaScript object: <cfscri...

2
голосов
1ответов
4459 просмотров

setting the maximum segment size in the tcp header

I am putting together a port scanner as a learning exercise. My problem is I'm trying to set the maximum segment size option(MSS) in the TCP header. I had a look at tcp.h, but I'm having trouble figuring out how to set it. I was hoping there would be an option like this: tcp_header->mss(3200...

1
голосов
3ответов
1219 просмотров

Mix of template and struct

I have a template class defined as follow : template <class T1, class T2> class MyClass { }; In this class, I need a struct that contains one member of type T1. How can I do that ? I tried the following, but it didn't work : template <class T1, class T2> class MyClass { typed...

34
голосов
8ответов
123189 просмотров

Char array in a struct - incompatible assignment?

I tried to find out what a struct really 'is' and hit a problem, so I have really 2 questions: 1) What is saved in 'sara'? Is it a pointer to the first element of the struct? 2) The more interesting question: Why doesn't it compile? GCC says "test.c:10: error: incompatible types in assignment"...

2
голосов
7ответов
610 просмотров

how to refer to the current struct in an overloaded operator?

I have a struct for which i want to define a relative order by defining , <= and>= operators. actually in my order there won't be any equality, so if one struct is not smaller than another, it's automatically larger. I defined the first operator like this: struct MyStruct{ ... ... bool ...

4
голосов
4ответов
4722 просмотров

How can I check if a struct has been initialized?

I'm using an NSRange (a struct) and initializing it like this: @interface MyViewController : UIViewController { NSRange currentRange; } NSRange has a location and length field. How can I check to see if the struct has been initialized with a value? I tried: if (myRange.length == nil) b...

0
голосов
2ответов
1034 просмотров

Serialize/marshal/reverse engineer unknown structure

Is there a way to deserialize or marshal or somehow parse a byte array back into a structure when you don't know what that structure was in the first place? The structure probably came from C++. Some background: I have a flight simulator for R/C planes and I'm trying to figure out if I can autom...

11
голосов
6ответов
7817 просмотров

Class factory to produce simple struct-like classes?

While investigating Ruby I came across this to create a simple Struct-like class: Person = Struct.new(:forname, :surname) person1 = Person.new('John', 'Doe') puts person1 #<struct Person forname="John", surname="Doe"> Which raised a few Python questions for me. I have written a [VERY] b...

1
голосов
3ответов
7051 просмотров

C++ byte stream

For a networked application, the way we have been transmitting dynamic data is through memcpying a struct into a (void*). This poses some problems, like when this is done to an std::string. Strings can be dynamic length, so how will the other side know when the string ends? An idea I had was to u...

0
голосов
2ответов
1365 просмотров

How do I pass a struct from an unmanaged C++ program to a C# program?

This is my second post. Here is what I am trying to do: Call an unmanaged c++ program from c#, passing in a array of structs from the c# program and return a updated version of the array of structs from the c++ program. Here is the calling c# program: using System; using System.Runtime.Intero...

59
голосов
3ответов
59318 просмотров

default visibility of C++ class/struct members

In C++, why is private the default visibility for members of classes, but public for structs?

10
голосов
11ответов
3784 просмотров

Pad a C++ structure to a power of two

I'm working on some C++ code for an embedded system. The I/O interface the code uses requires that the size of each message (in bytes) is a power of two. Right now, the code does something like this (in several places): #pragma pack(1) struct Message { struct internal_ { unsigned l...

14
голосов
5ответов
33770 просмотров

How to use a struct in C?

This is code for a linked list in the C programming language. #include <stdio.h> /* For printf */ #include <stdlib.h> /* For malloc */ typedef struct node { int data; struct node *next; /* Pointer to next element in list */ } LLIST; LLIST *list_add(LLIST **p, int i); v...

2
голосов
2ответов
1225 просмотров

read from file to array of structs within structs in C++

I have asked this question previously here and a similar question was closed. SO based on a comment from another user, I have reframed my question: In the first post, I was trying to read tha data from a file into an array with a struct.By using indata <> p.fId, I was able to read values ...

0
голосов
2ответов
4685 просмотров

Reading data from file into array of structs C++

I have a sample txt file and want to read the contents of the file into an array of structs. My persons.txt file contains 5 arbitrary nos one on each line. 7 6 4 3 2 My program looks like this: #include <iostream> #include <fstream> using namespace std; struct PersonId { ty...

2
голосов
5ответов
3931 просмотров

std::sort and binary '=' operator issue with a C++ struct

Ok... I have this struct and comparison function- struct Edge { char point1; char point2; int weight; bool operator<( const Edge& rhs ) const { return( weight < rhs.weight ); } }; //end Edge bool compare...

3
голосов
6ответов
15333 просмотров

Sending structure using recvfrom() and sendto()

I am using C language which is a common platform for both the server and the client. I have a structure of a particular type which I want to send to the client from the server. For e.g. SERVER CODE //necessary declarations struct hostent *hp; hp=gethostbyname("www.google.com"); sendto(soc...

18
голосов
5ответов
8147 просмотров

Why can TimeSpan and Guid Structs be compared to null?

I've noticed that some .NET structs can be compared to null. For example: TimeSpan y = new TimeSpan(); if (y == null) return; will compile just fine (the same with the Guid struct). Now I know that stucts are value type and that the code above should not compile, unless t...

1
голосов
5ответов
1622 просмотров

How to create a structure with two variable sized arrays in C

I am writing a light weight serialization function and need to include two variable sized arrays within this. How should I track the size of each? How should I define the struct? Am I going about this all wrong? EDIT: the result must be a contiguous block of memory

129
голосов
10ответов
33058 просмотров

Why don't structs support inheritance?

I know that structs in .NET do not support inheritance, but its not exactly clear why they are limited in this way. What technical reason prevents structs from inheriting from other structs?

4
голосов
3ответов
12848 просмотров

How do I get the FieldInfo of an array field?

I'm trying to get the field info of an array value from within a struct. So far I have the following, but I dont see how to get the infomration I want. [StructLayout(LayoutKind.Sequential)] public struct Test { public byte Byte1; [MarshalAs(UnmanagedType.ByValArray, ...

2
голосов
7ответов
251 просмотров

Structs With Constraints

I've had a hard time figuring out how I can write a struct in C# that has constraints on its fields' values. For example, System.DateTime DateTime d = new DateTime(); puts the value 01/01/0001 12:00:00 AM in d. But I can't write an explicit parameterless constructor, as structs are not allow...

0
голосов
5ответов
1004 просмотров

c struct grabbing data by offset

Lets say I have this struct: typedef struct nKey { int num; widget* widget; } NUMBER_KEY; and a function: void dialKey(widget* widget) { // Need to print 'num' of the struct that this widget resides in } How do I go about accomplishing this? I tried something like: printf("...

-1
голосов
3ответов
403 просмотров

C# struct initialization with compile error but runs correctly

Inside XNA struct Vector2 are two public variables X and Y. I have the following code: Vector2 v; if(b) v.X=1; else v.Y=2; //use v The compiler gives "Use of unassigned local variable 'v'" But it runs correctly nonetheless. Is there a more correct way of doing it?

6
голосов
3ответов
2299 просмотров

Sizes of structs on 32 bit and 64 bit

In the .NET struct design guidelines, it gives the maximum sensible size of a struct as 16 bytes. How do you determine how large your struct is, and is it affected by the architecture your program is running on? Is this value 32-bit only, or for both archs?

3
голосов
2ответов
13119 просмотров

Structure prototype?

How do I put a struct in a separate file? I can do it with functions by putting the function prototype in a header file e.g. file.h and the function body in a file like file.cpp and then using the include directive #include "file.h" in the source file with main. Can anybody give a simple example ...

3
голосов
4ответов
7847 просмотров

Pointer to struct within the nested structs

I'm trying to run the following code(in gcc 4.3 on fedora 11 i586 ): #include <stdio.h> #include <stdint.h> #include <stdlib.h> struct s_smallstruct{ int smallstruct; }; struct s_test2{...

4
голосов
2ответов
2641 просмотров

Exposing C# struct to COM breaks for VB6 app

Last Updated: 2009-08-11 2:30pm EDT A few days ago I posted this question about some very strange problems. Well, I figured out what specifically was causing a build on one machine to not run on others and even came up with a work-around, but now it leaves me with a nice, specific question: Why?...

187
голосов
9ответов
64186 просмотров

When should I use Struct vs. OpenStruct?

In general, what are the advantages and disadvantages of using an OpenStruct as compared to a Struct? What type of general use-cases would fit each of these?