473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Source

What does the following code mean?

struct GUID *guid ={0};

Is it similar to a C++ virtual function?

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #1
34 1889
Bill Cunningham <no****@net.net> scribbled the following:
What does the following code mean? struct GUID *guid ={0};
It initialises a pointer to struct GUID, whatever struct GUID is. The
pointer is currently not pointing at any struct GUID.
Is it similar to a C++ virtual function?


No.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"To doo bee doo bee doo."
- Frank Sinatra
Nov 13 '05 #2
"Bill Cunningham" <no****@net.net> wrote in
news:3f********@corp.newsgroups.com:
What does the following code mean?

struct GUID *guid ={0};

Is it similar to a C++ virtual function?


No. It means, create a pointer to a struct GUID and initialize this new
pointer to 0. The {} are not necessary here. I'd write this as:

struct GUID *pGuid = NULL;

But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };

or

struct GUID guid;

memset(guid, 0, sizeof guid);

--
- Mark ->
--
Nov 13 '05 #3
"Bill Cunningham" <no****@net.net> wrote in message
news:3f********@corp.newsgroups.com...
What does the following code mean?

struct GUID *guid ={0};
Create an object of type 'pointer to struct GUID',
and initialize it to NULL. (the braces are optional).
Is it similar to a C++ virtual function?


Not at all. Nothing to do with a function of any kind.

-Mike
Nov 13 '05 #4

"Mark A. Odell" <no****@embeddedfw.com> wrote in message
news:Xn*******************************@130.133.1.4 ...
"Bill Cunningham" <no****@net.net> wrote in
news:3f********@corp.newsgroups.com:
What does the following code mean?

struct GUID *guid ={0};

Is it similar to a C++ virtual function?


No. It means, create a pointer to a struct GUID and initialize this new
pointer to 0. The {} are not necessary here. I'd write this as:

struct GUID *pGuid = NULL;

But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };

or

struct GUID guid;

memset(guid, 0, sizeof guid);

Then C is an object language.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #5

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
What does the following code mean?

struct GUID *guid ={0};


It initialises a pointer to struct GUID, whatever struct GUID is. The
pointer is currently not pointing at any struct GUID.

A struct GUID then, how would one write it. The GUID comes from MS's COM.

struct GUID (int x,int y);
The GUID struct is already defined in COM but that doesn't help me learn the
concept of struct. What I've seen looks like data type declarations and no
functions.

struct A{
int a;
char b;
double c;};

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #6
Bill Cunningham <no****@net.net> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
> What does the following code mean?
> struct GUID *guid ={0};


It initialises a pointer to struct GUID, whatever struct GUID is. The
pointer is currently not pointing at any struct GUID.

A struct GUID then, how would one write it. The GUID comes from MS's COM.

struct GUID (int x,int y);
This is a syntax error in C. Would you be wanting comp.lang.c++?
The GUID struct is already defined in COM but that doesn't help me learn the
concept of struct. What I've seen looks like data type declarations and no
functions. struct A{
int a;
char b;
double c;};


Structs are different things in C and C++. Pick a language. If it's
really C then reply again and I will explain what structs are in C.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"The trouble with the French is they don't have a word for entrepreneur."
- George Bush
Nov 13 '05 #7

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
> What does the following code mean?

> struct GUID *guid ={0};

It initialises a pointer to struct GUID, whatever struct GUID is. The
pointer is currently not pointing at any struct GUID.
A struct GUID then, how would one write it. The GUID comes from MS's COM.
struct GUID (int x,int y);


This is a syntax error in C. Would you be wanting comp.lang.c++?
The GUID struct is already defined in COM but that doesn't help me learn

the concept of struct. What I've seen looks like data type declarations and no functions.

struct A{
int a;
char b;
double c;};


Structs are different things in C and C++. Pick a language. If it's
really C then reply again and I will explain what structs are in C.


C of course. This is clc. What I was saying was that I never see functions
in structs. Just declared data types.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #8
On Thu, 09 Oct 2003 19:22:20 +0000, Mark A. Odell wrote:
But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };
Ok.
or

struct GUID guid;
memset(guid, 0, sizeof guid);


This isn't a very good idea.

Nov 13 '05 #9
Bill Cunningham <no****@net.net> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
> news:bm**********@oravannahka.helsinki.fi...
>> Bill Cunningham <no****@net.net> scribbled the following:
>> > What does the following code mean?
>>
>> > struct GUID *guid ={0};
>>
>> It initialises a pointer to struct GUID, whatever struct GUID is. The
>> pointer is currently not pointing at any struct GUID.
>>
> A struct GUID then, how would one write it. The GUID comes from MS's COM.
> struct GUID (int x,int y);
This is a syntax error in C. Would you be wanting comp.lang.c++?


Did you read this bit?
> The GUID struct is already defined in COM but that doesn't help me learn the > concept of struct. What I've seen looks like data type declarations and no > functions.

> struct A{
> int a;
> char b;
> double c;};


Structs are different things in C and C++. Pick a language. If it's
really C then reply again and I will explain what structs are in C.

C of course. This is clc. What I was saying was that I never see functions
in structs. Just declared data types.


If it's C then your compiler will choke on:
struct GUID (int x, int y);
The fact that there aren't any functions declared inside that struct
GUID doesn't help. It won't magically make the C compiler accept syntax
errors.
Therefore I still suspect your code is really C++.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"O pointy birds, O pointy-pointy. Anoint my head, anointy-nointy."
- Dr. Michael Hfuhruhurr
Nov 13 '05 #10
Sheldon Simms <sh**********@yahoo.com> wrote in
news:pa****************************@yahoo.com:
But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };


Ok.
or

struct GUID guid;
memset(guid, 0, sizeof guid);


This isn't a very good idea.


Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.

--
- Mark ->
--
Nov 13 '05 #11
"Bill Cunningham" <no****@net.net> wrote in
news:3f********@corp.newsgroups.com:
> What does the following code mean?
>
> struct GUID *guid ={0};
>
> Is it similar to a C++ virtual function?


No. It means, create a pointer to a struct GUID and initialize this new
pointer to 0. The {} are not necessary here. I'd write this as:

struct GUID *pGuid = NULL;

But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };

or

struct GUID guid;

memset(guid, 0, sizeof guid);

Then C is an object language.


I should have used the word struct instead of object but I meant object in
a generic term, not in the C++ Object Oriented manner. C is not an object
oriented langauge "out of the box".

--
- Mark ->
--
Nov 13 '05 #12
"Bill Cunningham" <no****@net.net> wrote in
news:3f********@corp.newsgroups.com:

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
> news:bm**********@oravannahka.helsinki.fi...
>> Bill Cunningham <no****@net.net> scribbled the following:
>> > What does the following code mean?
>>
>> > struct GUID *guid ={0};
>>
>> It initialises a pointer to struct GUID, whatever struct GUID is.
>> The pointer is currently not pointing at any struct GUID.
>>
> A struct GUID then, how would one write it. The GUID comes from MS's COM.
> struct GUID (int x,int y);


This is a syntax error in C. Would you be wanting comp.lang.c++?
> The GUID struct is already defined in COM but that doesn't help me
> learn

the > concept of struct. What I've seen looks like data type declarations
> and no > functions.

> struct A{
> int a;
> char b;
> double c;};


Structs are different things in C and C++. Pick a language. If it's
really C then reply again and I will explain what structs are in C.


C of course. This is clc. What I was saying was that I never see
functions in structs. Just declared data types.


Correct. Problem with that? You can "fake" it by putting pointers to
functions in your structs and then filling in the struct, e.g.

#include <stdio.h>

enum AppleTypes { GRANNY_SMITH, DELICIOUS, MACINTOSH };

struct Apple
{
int count;
enum AppleTypes type;
void (*init)(struct Apple *pApple);
};

static void appleInit(struct Apple *pApple)
{
pApple->count = 1234;
pApple->type = GRANNY_SMITH;
}

int main(void)
{
struct Apple apple;

apple.init = appleInit;
apple.init(&apple);

printf("Apple count is %d\n", apple.count);

return 0;
}

--
- Mark ->
--
Nov 13 '05 #13
Mark A. Odell wrote:
Sheldon Simms <sh**********@yahoo.com> wrote in
news:pa****************************@yahoo.com:
struct GUID guid;
memset(guid, 0, sizeof guid);


This isn't a very good idea.

Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.


What's wrong with it?

Nov 13 '05 #14

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi...
Bill Cunningham <no****@net.net> scribbled the following:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
> news:bm**********@oravannahka.helsinki.fi...
>> Bill Cunningham <no****@net.net> scribbled the following:
>> > What does the following code mean?
>>
>> > struct GUID *guid ={0};
>>
>> It initialises a pointer to struct GUID, whatever struct GUID is. The >> pointer is currently not pointing at any struct GUID.
>>
> A struct GUID then, how would one write it. The GUID comes from MS's COM.

> struct GUID (int x,int y);

This is a syntax error in C. Would you be wanting comp.lang.c++?
Did you read this bit?
The GUID struct is already defined in COM but that doesn't help me
learn the
> concept of struct. What I've seen looks like data type declarations
and no
> functions.

> struct A{
> int a;
> char b;
> double c;};

Structs are different things in C and C++. Pick a language. If it's
really C then reply again and I will explain what structs are in C.
C of course. This is clc. What I was saying was that I never see

functions in structs. Just declared data types.


If it's C then your compiler will choke on:
struct GUID (int x, int y);


I think he meant struct GUID {int x, int y};

The fact that there aren't any functions declared inside that struct
GUID doesn't help. It won't magically make the C compiler accept syntax
errors.
Therefore I still suspect your code is really C++.

Nov 13 '05 #15
Bill Cunningham wrote:
Then C is an object language.

C has objects. It, with some pain, can do object-oriented programming.
OO is not a natural idiom for C programming. If you want to do OO, there
are better languages.

Brian Rodenborn
Nov 13 '05 #16

On Thu, 9 Oct 2003, Ashish wrote:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote...
> Bill Cunningham <no****@net.net> scribbled the following:
>
> > struct GUID (int x,int y);
>
> This is a syntax error in C. Would you be wanting comp.lang.c++?


I think he meant struct GUID {int x, int y};


That's still a syntax error in C.
But in C++, one can legally write

struct GUID
{
GUID (int x, int y); // <-- this line
};

which is very close to what Bill wrote.
In C, one can legally write

struct GUID { int x; int y; };

which is also similar (but of course
means something completely different).

-Arthur
Nov 13 '05 #17
On 9 Oct 2003 20:48:02 GMT, "Mark A. Odell" <no****@embeddedfw.com>
wrote:
Sheldon Simms <sh**********@yahoo.com> wrote in
news:pa****************************@yahoo.com:
But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };


Ok.
or

struct GUID guid;
memset(guid, 0, sizeof guid);


This isn't a very good idea.


Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.


I used to do that too (back in the day using an old VAX C compiler),
but I always use the first form now. It's simpler, cleaner and works
just fine.

- Sev

Nov 13 '05 #18
On Thu, 9 Oct 2003 15:51:02 -0400, in comp.lang.c , "Bill Cunningham"
<no****@net.net> wrote:

"Mark A. Odell" <no****@embeddedfw.com> wrote in message
news:Xn*******************************@130.133.1. 4...

But if I actually wanted a GUID object,

Then C is an object language.


C defines "Object" thus.
3.14
1 object
region of data storage in the execution environment, the contents of
which can represent values

Note that this has NOTHING to do with being object-oriented which is I
suspect what you meant.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #19
On Thu, 09 Oct 2003 21:15:32 GMT, in comp.lang.c , Matt Gregory
<bl****************@earthlink.net> wrote:
Mark A. Odell wrote:
Sheldon Simms <sh**********@yahoo.com> wrote in
news:pa****************************@yahoo.com:
struct GUID guid;
memset(guid, 0, sizeof guid);

This isn't a very good idea.

Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.


What's wrong with it?


all-bits-zero might be a trap representation or other invalid value
for one of the data types within the GUID structure. For instance,
all-bits-zero might represent "Not a Number" for floating point, so
that if you later on tried to read it, you'd possibly coredump.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #20
Ashish wrote:
> >> > What does the following code mean?
> >>
> >> > struct GUID *guid ={0};
> >>
> >> It initialises a pointer to struct GUID, whatever struct GUID is.
> >> The pointer is currently not pointing at any struct GUID.
> >>
> > A struct GUID then, how would one write it. The GUID comes from MS's
> > COM.
>
> > struct GUID (int x,int y);

It doesn't matter what struct GUID is because guid is only a *pointer*.
You are just initializing a pointer to the value 0. This is the same as

struct GUID *guid = 0;

or

int *p = 0;

for that matter.

[snip] If it's C then your compiler will choke on:
struct GUID (int x, int y);


I think he meant struct GUID {int x, int y};


That is still a syntax error. ITYM

struct GUID {int x; int y;};

However, this is a moot point.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Nov 13 '05 #21

> >> > What does the following code mean?
> >>
> >> > struct GUID *guid ={0};
> >>
> >> It initialises a pointer to struct GUID, whatever struct GUID is. The> >> pointer is currently not pointing at any struct GUID.
> >>
> > A struct GUID then, how would one write it. The GUID comes from MS's COM.
>
> > struct GUID (int x,int y);
>
> This is a syntax error in C. Would you be wanting comp.lang.c++?


Did you read this bit?
> > The GUID struct is already defined in COM but that doesn't help me learn the
> > concept of struct. What I've seen looks like data type declarations and no
> > functions.
>
> > struct A{
> > int a;
> > char b;
> > double c;};
>
> Structs are different things in C and C++. Pick a language. If it's
> really C then reply again and I will explain what structs are in C.

C of course. This is clc. What I was saying was that I never see functions in structs. Just declared data types.


If it's C then your compiler will choke on:
struct GUID (int x, int y);


I think he meant struct GUID {int x, int y};

The fact that there aren't any functions declared inside that struct
GUID doesn't help. It won't magically make the C compiler accept syntax
errors.
Therefore I still suspect your code is really C++.

What I'm really wanting to know I guess is how structs work and how to use
them. I used the GUID example.
For example.
typedef struct A{
int a;
double b;}/* sometimes a term */ ;
and I've seen struct A without the typedef.
What's the difference with and w/o the typedef? The structs hold data I can
see. How are they called? Is data all they hold?

This and pointers are the major sticking points for me with C. And when
there are bunches of parenthesis such as (((((*c))))))). That's confusing.
It looks like a time warp. Unions I rarely see.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #22

"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message
news:Pi***********************************@unix45. andrew.cmu.edu...

On Thu, 9 Oct 2003, Ashish wrote:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote...
>> Bill Cunningham <no****@net.net> scribbled the following:
>>
>> > struct GUID (int x,int y);
>>
>> This is a syntax error in C. Would you be wanting comp.lang.c++?
I think he meant struct GUID {int x, int y};


That's still a syntax error in C.
But in C++, one can legally write


Sorry, I meant struct GUID {int x; int y;};

struct GUID
{
GUID (int x, int y); // <-- this line
};

which is very close to what Bill wrote.
In C, one can legally write

struct GUID { int x; int y; };

which is also similar (but of course
means something completely different).

-Arthur

Nov 13 '05 #23
On Thu, 09 Oct 2003 23:50:41 +0100, Mark McIntyre
<ma**********@spamcop.net> wrote in comp.lang.c:
On Thu, 9 Oct 2003 15:51:02 -0400, in comp.lang.c , "Bill Cunningham"
<no****@net.net> wrote:

"Mark A. Odell" <no****@embeddedfw.com> wrote in message
news:Xn*******************************@130.133.1. 4...

But if I actually wanted a GUID object,

Then C is an object language.


C defines "Object" thus.
3.14
1 object
region of data storage in the execution environment, the contents of
which can represent values

Note that this has NOTHING to do with being object-oriented which is I
suspect what you meant.


....and C++ describes it equivalently, using more words:

1.8 The C++ object model
1 The constructs in a C++ program create, destroy, refer to, access,
and manipulate objects. An object is a region of storage. [Note: A
function is not an object, regardless of whether or not it occupies
storage in the way that objects do. ] An object is created by a
definition (3.1), by a new expression
(5.3.4) or by the implementation (12.2) when needed. The properties of
an object are determined when the object is created.
An object can have a name (clause 3). An object has a storage duration
(3.7) which influences its lifetime
(3.8). An object has a type (3.9). The term object type refers to the
type with which the object is created.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #24
Bill Cunningham wrote:
What I'm really wanting to know I guess is how structs work and how to use
them.
They work the same way ints work. They're just types, that's all.
I used the GUID example.
For example.
typedef struct A{
int a;
double b;}/* sometimes a term */ ;
This is a syntax error.

typedef struct A{
int a;
double b;} A;

would not be a syntax error, however. Here is the typedef again, this time
on a single line:

typedef struct A{ int a; double b;} A;

Here it is again, perhaps slightly less confusingly:

typedef struct A_tag { int a; double b;} A;
There are two parts here, which I'll separate out vertically for you:

xxxxxxx struct A_tag { int a; double b;} xx

typedef xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx A;

There's the typedef (something-as) A, and there's the struct definition.

Put them together, and you are defining A as an alias for struct A_tag.
and I've seen struct A without the typedef.
What's the difference with and w/o the typedef?
typedef creates a new synonym for an existing type. So, once the compiler
has seen the above example, you can use A wherever you would previously
have used struct A_tag - if you wish. To confuse matters, the tag is
allowed to be the same as the new type.
The structs hold data I
can see. How are they called?
You don't call a struct. It's just a bunch of data.
Is data all they hold?
Yes. That data can, in fact, include pointers to functions, but they're just
data too.
This and pointers are the major sticking points for me with C.
Get a better C book, then.
And when
there are bunches of parenthesis such as (((((*c))))))). That's confusing.


This reduces to *c)) which (on its own) is a syntax error. Don't be confused
by syntax errors. Just fix them.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #25
Mark A. Odell wrote:
struct GUID guid;
memset(guid, 0, sizeof guid);


This isn't a very good idea.


Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.


That's certainly an issue if the struct contains non-integer types, but I'm
more worried about compiler diagnostics. Look at your first argument to
memset again, more closely. Then look up the definition of memset.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #26
On Thu, 09 Oct 2003 21:15:32 GMT
Matt Gregory <bl****************@earthlink.net> wrote:
Mark A. Odell wrote:
Sheldon Simms <sh**********@yahoo.com> wrote in
news:pa****************************@yahoo.com:
struct GUID guid;
memset(guid, 0, sizeof guid);

This isn't a very good idea.

Are you concerned about traps? I suppose this may not be fully
portable but I admit I am guilty of doing this quite often.


What's wrong with it?


It sets all bits zero. Unfortunately all bits set to zero could be a
trap representation for some of the elements of struct GUID depending
on that type they are.
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.
Nov 13 '05 #27
In <Xn********************************@130.133.1.4> "Mark A. Odell" <no****@embeddedfw.com> writes:
Sheldon Simms <sh**********@yahoo.com> wrote in
news:pa****************************@yahoo.com:
But if I actually wanted a GUID object, and not a pointer to one,
initialzed to zero I'd need to write:

struct GUID guid = { 0 };


Ok.
or

struct GUID guid;
memset(guid, 0, sizeof guid);


This isn't a very good idea.


Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.


Not necessarily traps, but non-integer structure members may not be
initialised to zero or null pointers. Of course, this is an issue only
when portability to weird platforms is a valid concern (neither null
pointers nor floating point zero need be represented as all bits zero).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #28
Richard Heathfield <do******@address.co.uk.invalid> wrote in
news:bm**********@hercules.btinternet.com:
struct GUID guid;
memset(guid, 0, sizeof guid);

This isn't a very good idea.


Are you concerned about traps? I suppose this may not be fully portable
but I admit I am guilty of doing this quite often.


That's certainly an issue if the struct contains non-integer types, but
I'm more worried about compiler diagnostics. Look at your first argument
to memset again, more closely. Then look up the definition of memset.


Yikes!

memset(&guid, 0, sizeof guid);

I will, from this point forth, no longer use memset() on structs even if I
know it contains no data types that can have trap values.

--
- Mark ->
--
Nov 13 '05 #29
So the character after the last } of a struct and before ; is for a typedef?
What about this.

struct A{
int a;
*_point;}Ab; /* is the Ab an alias? */

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #30

On Fri, 10 Oct 2003, Bill Cunningham wrote:

So the character after the last } of a struct and before ;
is for a typedef? What about this.

struct A{
int a;
*_point;}Ab; /* is the Ab an alias? */

Are you the same Bill Cunningham who's been posting drivel
in this newsgroup since 1996?

I hate to echo ERT, but you really should work on making
a less obvious troll; otherwise people might ignore you.

-Arthur

Nov 13 '05 #31
"Bill Cunningham" <no****@net.net> wrote:
So the character after the last } of a struct and before ; is for a typedef?
What about this.

struct A{
int a;
*_point;}Ab; /* is the Ab an alias? */ ^^^
Syntax error!

Err, no: in this case 'Ab' is an object of type 'struct A';

What you probably meant is something like:

typedef
struct A
{
int a;
int *p;
}
Ab;

Here the identifier 'Ab' is defined as an alias for 'struct A', so you
can, for example, declare a variable of this type like this:

Ab bar;

instead of having to write:

struct A bar;
Of course the type you want to create an alias for does not have to be
a struct:

typedef
int
foo;

Here 'foo' is defined as type alias for int.

HTH
Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #32
What you probably meant is something like:

typedef
struct A
{
int a;
int *p;
}
Ab;

Here the identifier 'Ab' is defined as an alias for 'struct A', so you
can, for example, declare a variable of this type like this:

Ab bar;

instead of having to write:

struct A bar;
Of course the type you want to create an alias for does not have to be
a struct:

typedef
int
foo;

Here 'foo' is defined as type alias for int.

HTH
Regards

Ok great I see now thanks.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #33


Are you the same Bill Cunningham who's been posting drivel
in this newsgroup since 1996?
I dunno. Has it been that long? Only C drivel though.

I hate to echo ERT, but you really should work on making
a less obvious troll; otherwise people might ignore you.

-Arthur



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #34
Arthur J. O'Dwyer wrote:

On Fri, 10 Oct 2003, Bill Cunningham wrote:

So the character after the last } of a struct and before ;
is for a typedef? What about this.

struct A{
int a;
*_point;}Ab; /* is the Ab an alias? */

Are you the same Bill Cunningham who's been posting drivel
in this newsgroup since 1996?


The very briefest of perusals of the 1996 stuff suggests that it's written
by a different Bill Cunningham. This Bill Cunningham appears to have been
posting drivel only since 2002.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #35

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

Similar topics

9
by: FISH | last post by:
Ever have one of those days when you're not sure if it's you who's gone mad, or the rest of the world? I have an Open Source project on SourceForge for communication with YSMG - Yahoo's IM...
30
by: Hallvard B Furuseth | last post by:
Now that the '-*- coding: <charset> -*-' feature has arrived, I'd like to see an addition: # -*- str7bit:True -*- After the source file has been converted to Unicode, cause a parse error if a...
1
by: M.E.Farmer | last post by:
Hello c.l.py!, I have just finished this and decided to share. PySourceColor is a module to convert Python source into colored html. Yes it has been done before, but I like this better:) You can...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
5
by: Pete Wason | last post by:
Hiall! I have a demo viewer page for javascript stuff that has three buttons "DEMO" "HTML" and "JSCR", and an IFRAME called 'viewer'. Initially, the IFRAME gets loaded with the actual demo...
2
by: Next | last post by:
Hello all, I have a windows service that was suppose to write some events into its own EventLog. I created the EventLog using the component on VS 2003 toolbar Added an installer for it. Set...
8
by: Alvo von Cossel I | last post by:
hey everybody, I have written a great browser but it is missing a feature (quite a lot actually, but forget about them for now). that feature just so happens to be the View > Source function....
1
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.