473,796 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

structs help

Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

just to test in my main method I tried to initialize the
listNodePtr variable to null like this...

listNodePtr *head = NULL;

First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
that listNodePtr is an alias to the struct ln. So my statement
above should be legal. Is It?

When I try to pass my new listNodePtr variable *head to my
listInsert method like........

listInsert(head ,1,2);

it doesn't work. It builds but at run time my program hangs
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.

The method definition looks like...

void listInsert(list NodePtr *list, int key, int value)

I am assuming the body of the method is correct as this code
was given to us to use by my Prof.

Please help what am I doing wrong during my initialization?
How do I use structs defined like the one above?

Thanks in advance.
Nov 14 '05
22 2060
>"Leor Zolman" <le**@bdsoft.co m> wrote in message
news:kf******* *************** **********@4ax. com...
I used the same name for the typedef as for the structure tag, because
that happens to me my own personal style; you might choose to do
otherwise, but this is perfectly legal.

In article <news:by******* *************@n ewsb.telia.net>
Chris Fogelklou <ch************ *@comhem.se> writes:Although some compilers don't like it (even if it is legal!)

I've had to go through code written for one compiler and edit all the struct
definitions for another one because all of the structures defined used the
same name and the second compiler didn't like it.

This was for an embedded system... can't remember the specific compiler...
The C standards (original ANSI C89, ISO C90, and ISO C99) are quite
clear: structure tag names are in a separate name space and *must*
not interfere with any other identifiers in the ordinary name space
used for variables, functions, and typedef-names. So this particular
compiler was just plain broken.

Of course, if you have to use a broken tool, you have to use a
broken tool. :-) But I would put this next bit differently:
anyway, for best code portability, use different names:

typedef struct my_struct_tag {
int my_int;
float my_float;
} my_struct_t, *p_my_struct_t;


As I like to point out, the real problem with typedef is that it
lies to humans and confuses them.

First, the keyword itself has the wrong name: it does not define
a type, but rather changes variable declarations into aliases for
some existing type(s):

int a, *b, c[3]; /* declare a as int, *b as int (and thus
b as pointer to int), c[i] as int (and thus c as array of
int, with the number of elements in the array being 3) */

typedef int a, *b, c[3]; /* change the above "declare ... as"
to "declare ... as an alias for": a is an alias for int,
b is an alias for pointer-to-int, and c is an alias for
array-3-of-int. */

This is even more pronounced in the "typedef struct ..." sequence,
where people seem to believe that the typedef is creating the new
type. It is not -- it is the "struct ..." part that creates the
new type.

Second, the syntax for using a typedef'ed name is also confusing.
As I noted in an earlier posting, it becomes impossible to look at
a code fragment and decide a priori whether something is a declaration:

int(i),(*p)[3]; /* just to show parentheses in declarations */
zorgle(blat);

The second line, which looks like a function call, changes meaning
if "zorgle" is a typedef:

typedef char *zorgle;
...
zorgle(blat); /* same as "char *blat; */

(Of course, if this code appears outside of a function, a function
call is not allowed here anyway -- at least, not in C. Other languages
that strongly resemble C *do* allow function calls in such positions.)

As with macros like:

#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef-names can surprise one if one is not aware that they *are*
typedef-names, so it is often wise to choose some marker to say
"beware, this is a typedef-name" -- just as many C programmers
write the MIN macro above in uppercase, to let other programmers
know that:

i = MIN(read_input( ), x++);

is unlikely to do anything good.

The "typedef suffix" _t in Chris Fogelklou's examples is just such
a marker. If one uses it consistently, one can recognize:

zorgle_t (blat);

as a declaration (with unnecessary parentheses) without having to
go look to see whether zorgle_t is in fact a typedef. The _t suffix
tells you that it must be. (If it is not, the code is simply wrong
and needs to be fixed.)

My own preferred method is to type out the keyword "struct" each
time. I do have one exception to this: if a type-name is going to
be used heavily within a given program, so that anyone working on
that program is going to have to be aware that it *is* a type-name,
then it becomes OK to use a shorter name, even without any special
syntactic markings (such as an _t suffix or leading uppercase
letter).

The idea here is that I expect anyone working on *any* C program
to know that the C integral types are char, short, int, long, and
their explicit-sign variants (e.g., signed char and unsigned int),
the floating point types are float, double, and long double, and
for C99, the whole series of complex types, and so on. At the same
time, though, I expect any programmer working on the zorgle program
to know that the zorgle system uses a "zorgle" type with various
"semi-abstract datatype" features. If the program happens to use
some ancillary internal types in places, those might just have to
spell out the word "struct", and I might even use "struct zorgle"
anyway for the "well-known" zorgle type -- but because the type is
pervasive, it is OK to relax the "spell out the struct keyword"
rule.

This is, of course, a matter of taste. C *compilers* can keep
straight which identifiers have been typedef-aliased; whether you,
as a C programmer, choose some set(s) of rule(s) to make sure
that mere humans can also keep them straight is up to you.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #11
On 4 Apr 2004 15:42:17 GMT, Chris Torek <no****@torek.n et> wrote:

[snipped wonderful essay on pros and cons of using typedef]

Thanks, Chris, that was really good. I've even got a title for you, in case
we find a place to publish that (it ought to be required reading for anyone
starting to use typedef):

"typedef Considered Harmful - Unless..."

-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #12
On 4 Apr 2004 15:42:17 GMT, Chris Torek <no****@torek.n et> wrote:

[snipped wonderful essay on pros and cons of using typedef]

Thanks, Chris, that was really good. I've even got a title for you, in case
we find a place to publish that (it ought to be required reading for anyone
starting to use typedef):

"typedef Considered Harmful - Unless..."

-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #13
On Sat, 03 Apr 2004 22:36:05 -0600, Dave Cooke
<dc****@ee.uman itoba.ca> wrote:
Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

just to test in my main method I tried to initialize the
C does not have methods. It has functions.
listNodePtr variable to null like this...

listNodePtr *head = NULL;

First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
No. No neither is a variable. listNode is a typedef (a type alias)
for the type struct ln. listNodePtr is an alias for the type struct
ln*. *listNodePtr is exactly the same type as listNode.
that listNodePtr is an alias to the struct ln. So my statement
No, as noted above, it is an alias to the type struct ln*.
above should be legal. Is It?
Yes it is legal. (Your compiler did not generate a syntax error, did
it?) head has type struct ln** or pointer to pointer to struct ln.
Is it what you want? We can't tell; you did not show us the code that
uses it. Post a compilable program that exhibits the behavior you are
asking about.

When I try to pass my new listNodePtr variable *head to my
listInsert method like........

listInsert(hea d,1,2);

it doesn't work. It builds but at run time my program hangs
It either builds or it hangs. I have yet to see a program do both.
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.
Does it quit or does it hang?

From what little code you have shown, this invokes undefined behavior.
The variable head in main is passed as an argument to listInsert,
corresponding to the parameter list. Both have the type struct ln**.
head is initialized to NULL. Therefore, this is the value assigned to
list at entry to listInsert. Your code attempts to dereference list
(that is what *list means). You are not allowed to dereference a NULL
pointer.

Your comment says you want to determine if list is NULL. You do that
with
if (list == NULL) ...

The method definition looks like...

void listInsert(list NodePtr *list, int key, int value)
Since C passes by value, how do you expect the results of this
function to be available to the calling function. Anything you do to
list will disappear as soon as listInsert returns.

I am assuming the body of the method is correct as this code
was given to us to use by my Prof.

Please help what am I doing wrong during my initialization?
How do I use structs defined like the one above?


Your post indicates some misconceptions about C. Some may be
considered simply semantic (methods vs functions). Others seem to be
more basic, such as pointer syntax.

When you declare a pointer (or typedef a pointer type), you use
the asterisk to indicate the variable or type is a pointer. When you
evaluate a pointer variable in your code, you do not use the asterisk
because in that context the asterisk means dereference the pointer.

As others have mentioned, using typedef to create a pointer alias
is strongly not recommended.

Functions that manipulate linked lists usually use the return type to
send information back to the calling function. If you set the return
type of listInsert to struct ln* (or the equivalent listNode*), you
could then change head and list to this type and return list from the
listInsert.

If you really want to use pointer to pointer in listInsert (there are
times when this may be desirable), you should change head but pass
&head as the argument. list will still be a struct ln** but:

When you evaluate list, you get the address of head, not the
contents of head.

When you dereference list with *list, you are no longer attempting
to dereference a NULL pointer. list points to head and when you
dereference list you get the value in head which is NULL which makes
your if statement correct.
<<Remove the del for email>>
Nov 14 '05 #14
On Sat, 03 Apr 2004 22:36:05 -0600, Dave Cooke
<dc****@ee.uman itoba.ca> wrote:
Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

just to test in my main method I tried to initialize the
C does not have methods. It has functions.
listNodePtr variable to null like this...

listNodePtr *head = NULL;

First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
No. No neither is a variable. listNode is a typedef (a type alias)
for the type struct ln. listNodePtr is an alias for the type struct
ln*. *listNodePtr is exactly the same type as listNode.
that listNodePtr is an alias to the struct ln. So my statement
No, as noted above, it is an alias to the type struct ln*.
above should be legal. Is It?
Yes it is legal. (Your compiler did not generate a syntax error, did
it?) head has type struct ln** or pointer to pointer to struct ln.
Is it what you want? We can't tell; you did not show us the code that
uses it. Post a compilable program that exhibits the behavior you are
asking about.

When I try to pass my new listNodePtr variable *head to my
listInsert method like........

listInsert(hea d,1,2);

it doesn't work. It builds but at run time my program hangs
It either builds or it hangs. I have yet to see a program do both.
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.
Does it quit or does it hang?

From what little code you have shown, this invokes undefined behavior.
The variable head in main is passed as an argument to listInsert,
corresponding to the parameter list. Both have the type struct ln**.
head is initialized to NULL. Therefore, this is the value assigned to
list at entry to listInsert. Your code attempts to dereference list
(that is what *list means). You are not allowed to dereference a NULL
pointer.

Your comment says you want to determine if list is NULL. You do that
with
if (list == NULL) ...

The method definition looks like...

void listInsert(list NodePtr *list, int key, int value)
Since C passes by value, how do you expect the results of this
function to be available to the calling function. Anything you do to
list will disappear as soon as listInsert returns.

I am assuming the body of the method is correct as this code
was given to us to use by my Prof.

Please help what am I doing wrong during my initialization?
How do I use structs defined like the one above?


Your post indicates some misconceptions about C. Some may be
considered simply semantic (methods vs functions). Others seem to be
more basic, such as pointer syntax.

When you declare a pointer (or typedef a pointer type), you use
the asterisk to indicate the variable or type is a pointer. When you
evaluate a pointer variable in your code, you do not use the asterisk
because in that context the asterisk means dereference the pointer.

As others have mentioned, using typedef to create a pointer alias
is strongly not recommended.

Functions that manipulate linked lists usually use the return type to
send information back to the calling function. If you set the return
type of listInsert to struct ln* (or the equivalent listNode*), you
could then change head and list to this type and return list from the
listInsert.

If you really want to use pointer to pointer in listInsert (there are
times when this may be desirable), you should change head but pass
&head as the argument. list will still be a struct ln** but:

When you evaluate list, you get the address of head, not the
contents of head.

When you dereference list with *list, you are no longer attempting
to dereference a NULL pointer. list points to head and when you
dereference list you get the value in head which is NULL which makes
your if statement correct.
<<Remove the del for email>>
Nov 14 '05 #15
On Sun, 04 Apr 2004 07:33:12 -0400, Al Bowers wrote:


Dave Cooke wrote:
Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

just to test in my main method I tried to initialize the
listNodePtr variable to null like this...

listNodePtr *head = NULL;


The typedef has you confused.
Here head would be an alias for type
struct ln **

What you wnat is
listNodePtr head;

First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
that listNodePtr is an alias to the struct ln. So my statement
above should be legal. Is It?

When I try to pass my new listNodePtr variable *head to my
listInsert method like........

listInsert(head ,1,2);


The call would be:
listInsert(&hea d,1,2)
it doesn't work. It builds but at run time my program hangs
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.

The method definition looks like...

void listInsert(list NodePtr *list, int key, int value)

This function looks ok except I would change the value type to
represent success on the Insert.

Example:
#include <stdlib.h>
#include <stdio.h>

typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

int listInsert( listNodePtr *p, int key, int data);
void printList(listN odePtr p);
void freeList(listNo dePtr *p);

int main(void)
{
listNodePtr head = NULL;
listNode cp = {0}; /* to store a copy of head's values */

listInsert(&hea d,1,31);
listInsert(&hea d, 5,45);
listInsert(&hea d, 6,48);
printList(head) ;
if(head != NULL)
{
cp = *head;
freeList(&head) ;
if(head == NULL) puts("\nAfter freeing head, head = NULL");
puts("cp has a copy of head's member values");
printf("cp.key = %d\t\tcp.data = %d\n",cp.key,cp .data);
}
return 0;
}
int listInsert( listNodePtr *p, int key, int data)
{
listNodePtr new;

new = malloc(sizeof *new);
if(new == NULL) return 0;
new->key = key;
new->data = data;
new->next = *p;
*p = new;
return 1;
}

void printList(listN odePtr p)
{
size_t i;

for(i = 1 ; p ; i++, p = p->next)
printf("%u. key = %d\t\tdata = %d\n",
i,p->key, p->data);
return;
}

void freeList(listNo dePtr *p)
{
listNodePtr tmp;

for( ; *p ;*p = tmp )
{
tmp = (*p)->next;
free(*p);
}
return;
}


Sorry for not getting back to you guys,
WOW a night full of headache's is gone!
.....sort of...I guess I just will have to
create new ones!.

Thanks for the code examples. I am soooo
used to Java and C++. C++ I have to manage
pointers but C is sooo much different.

Thanks for the tip on the return type for the
"functions" :). It makes perfect sense.

Its frustrating when you have your algorithm worked
out on paper but you can't implement it cause you
don't know the language you are supposed to use!

You saved my lots of time thanks again.

Dave


Nov 14 '05 #16
On Sun, 04 Apr 2004 07:33:12 -0400, Al Bowers wrote:


Dave Cooke wrote:
Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

just to test in my main method I tried to initialize the
listNodePtr variable to null like this...

listNodePtr *head = NULL;


The typedef has you confused.
Here head would be an alias for type
struct ln **

What you wnat is
listNodePtr head;

First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
that listNodePtr is an alias to the struct ln. So my statement
above should be legal. Is It?

When I try to pass my new listNodePtr variable *head to my
listInsert method like........

listInsert(head ,1,2);


The call would be:
listInsert(&hea d,1,2)
it doesn't work. It builds but at run time my program hangs
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.

The method definition looks like...

void listInsert(list NodePtr *list, int key, int value)

This function looks ok except I would change the value type to
represent success on the Insert.

Example:
#include <stdlib.h>
#include <stdio.h>

typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

int listInsert( listNodePtr *p, int key, int data);
void printList(listN odePtr p);
void freeList(listNo dePtr *p);

int main(void)
{
listNodePtr head = NULL;
listNode cp = {0}; /* to store a copy of head's values */

listInsert(&hea d,1,31);
listInsert(&hea d, 5,45);
listInsert(&hea d, 6,48);
printList(head) ;
if(head != NULL)
{
cp = *head;
freeList(&head) ;
if(head == NULL) puts("\nAfter freeing head, head = NULL");
puts("cp has a copy of head's member values");
printf("cp.key = %d\t\tcp.data = %d\n",cp.key,cp .data);
}
return 0;
}
int listInsert( listNodePtr *p, int key, int data)
{
listNodePtr new;

new = malloc(sizeof *new);
if(new == NULL) return 0;
new->key = key;
new->data = data;
new->next = *p;
*p = new;
return 1;
}

void printList(listN odePtr p)
{
size_t i;

for(i = 1 ; p ; i++, p = p->next)
printf("%u. key = %d\t\tdata = %d\n",
i,p->key, p->data);
return;
}

void freeList(listNo dePtr *p)
{
listNodePtr tmp;

for( ; *p ;*p = tmp )
{
tmp = (*p)->next;
free(*p);
}
return;
}


Sorry for not getting back to you guys,
WOW a night full of headache's is gone!
.....sort of...I guess I just will have to
create new ones!.

Thanks for the code examples. I am soooo
used to Java and C++. C++ I have to manage
pointers but C is sooo much different.

Thanks for the tip on the return type for the
"functions" :). It makes perfect sense.

Its frustrating when you have your algorithm worked
out on paper but you can't implement it cause you
don't know the language you are supposed to use!

You saved my lots of time thanks again.

Dave


Nov 14 '05 #17
On Sun, 04 Apr 2004 16:41:47 +0000, Leor Zolman wrote:
On 4 Apr 2004 15:42:17 GMT, Chris Torek <no****@torek.n et> wrote:

[snipped wonderful essay on pros and cons of using typedef]

Thanks, Chris, that was really good. I've even got a title for you, in case
we find a place to publish that (it ought to be required reading for anyone
starting to use typedef):

"typedef Considered Harmful - Unless..."

-leor


Thanks Chris and Leor for the clarification. It has helped,
de-confuse this human....at least a little anyway.
Now on to the next confusing part trying to build a "simple"
memory manager for my next "AND LAST!" assignment :).

Thanks again.

Dave

Nov 14 '05 #18
On Sun, 04 Apr 2004 16:41:47 +0000, Leor Zolman wrote:
On 4 Apr 2004 15:42:17 GMT, Chris Torek <no****@torek.n et> wrote:

[snipped wonderful essay on pros and cons of using typedef]

Thanks, Chris, that was really good. I've even got a title for you, in case
we find a place to publish that (it ought to be required reading for anyone
starting to use typedef):

"typedef Considered Harmful - Unless..."

-leor


Thanks Chris and Leor for the clarification. It has helped,
de-confuse this human....at least a little anyway.
Now on to the next confusing part trying to build a "simple"
memory manager for my next "AND LAST!" assignment :).

Thanks again.

Dave

Nov 14 '05 #19


Barry Schwarz wrote:
On Sat, 03 Apr 2004 22:36:05 -0600, Dave Cooke
<dc****@ee.uman itoba.ca> wrote:

Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

just to test in my main method I tried to initialize the

C does not have methods. It has functions.

listNodePtr variable to null like this...

listNodePtr *head = NULL;
I suspect the OP wants:
listNodePtr head = NULL;

When I try to pass my new listNodePtr variable *head to my
listInsert method like........

listInsert(he ad,1,2);
The call:
listInsert(&hea d,1,2);

The method definition looks like...

void listInsert(list NodePtr *list, int key, int value)

Since C passes by value, how do you expect the results of this
function to be available to the calling function. Anything you do to
list will disappear as soon as listInsert returns.


Actually this prototype looks correct. It can modify a variable
in the calling function.
For example in the following, the value of head will be modified
should the function listInsert successfully allocate storage.

#include <stdlib.h>
#include <stdio.h>

typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;

void listInsert( listNodePtr *p, int key, int data);

int main(void)
{
listNodePtr head = NULL;

printf("In Main: Before call to listInsert function head"
" is %sNULL\n", head?"not ":"");
listInsert(&hea d,1,31);
printf("In Main: After call to listInsert function head"
" is %sNULL\n", head?"not ":"");
free(head);
return 0;
}
void listInsert( listNodePtr *p, int key, int data)
{
listNodePtr new;

new = malloc(sizeof *new);
if(new != NULL)
{
new->key = key;
new->data = data;
new->next = *p;
*p = new;
}
return;
}

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3406
by: Roman Hartmann | last post by:
hello, I do have a question regarding structs. I have a struct (profil) which has a pointer to another struct (point). The struct profil stores the coordinates of points. The problem is that I don't know how many points there will be in every struct in the end, so I have to allocate memory dynamically for them and can't use an array of fixed size, unfortunately. I would like to know if there is a better way to access struct members...
10
2078
by: Angel | last post by:
I'm using several C functions (in a dll) that receive a struct as parameter. Since I'm doing it in C#, I assume I need to recreate the struct in C# in order to call the function with the required parameter. What would I need to do in order to convert a struct that looks like this: typedef struct { char rsvd0; char iadl1;
6
3919
by: marabo82 | last post by:
Hi, i know that typedef structs creates an aliases for a particular struct in C++. i m trying to convert .h c++ files to a namespace in C#.net so that i use C++ DLL in my C# application. one of the structs in C++ is something like typedef struct mystruct {....} mystruct1, *mystruct2; since typedef is used, mystruct1 and *mystruct2 are aliases to mystruct. how can i acheive the same (i.e aliasses in c#)? i can subtitute mystruct1 and...
3
1420
by: marabo82 | last post by:
Hi, i know that typedef structs creates an aliases for a particular struct in C++. i m trying to convert .h c++ files to a namespace in C#.net so that i use C++ DLL in my C# application. one of the structs in C++ is something like typedef struct mystruct {....} mystruct1, *mystruct2; since typedef is used, mystruct1 and *mystruct2 are aliases to mystruct. how can i acheive the same (i.e aliasses in c#)? i can subtitute mystruct1 and...
5
2640
by: Steve Edwards | last post by:
Hi, With much help from this forum I've been using stl containers, but always with other common - or stl - types as members. I've now run in to a problem while trying to use some of my own structures: enum MySym{symA, symB, symC, symD ... etc.} typedef struct{ MySym s1, s2, s3;
61
3783
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch (myBranch + x) = new Branch(i); // it doesn't x is a loop iterator, i is an int for the constructor to define an array. What am I doing wrong here.
4
1771
by: engggirl3000 | last post by:
I was told to write a function that will read data, in a user defined text file, into a vector of structs. I am not sure where to start with this. Could some one tell me what is a vector of structs, I know vectors and I know structs, but I dont know whats a vector of structs. As well, is there a specific algoritm in c++ to use when reading from a user defined text file, or does cin work? If someone can give me a few pointers to help get...
29
2792
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much overhead (I think). A Struct seems more appropriate. At least it is what I would have used in other languages. But since a Struct *can* hold methods, I wander if I am saving anything. If not, why use it?
1
4771
by: radskate360 | last post by:
Hi I am newer to programming and need a bit of help with this program. OK, heres the directions. The distance between two places on earth can be calculated by using their latitudes and longitudes. The calculation for this is as follows: (The latitudes and longitudes must be converted to radians (radians=degrees * pi / 180)). PI must be set set to 20 decimals as follows: PI = 3.1419265358979323846 Earth's Radius = 3963.1
2
4359
by: jonpb | last post by:
Using .NET 3.5, I need to pass an array of structs as parameter to a C++ unmanaged function. The C++ dll stores some data in an unmanaged cache, the function writes the values into the array of structs. The array of structs are allocated by C#. If I pass the array without 'ref' it works fine on the C++ side, but after returning to C# the array struct values are all zero. If I pass with 'ref' the application crashes. If I use a class...
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.