Correct Typedef

A

abhishekkabra

If your problem is exactly like what you have given in example
then

1. First your function defination is wrong . It should be taking
argument pointer to pointer to structure like **Ob
2.You only give function declaration So Complier assumes that there may
be any defination also ( but i guess this is not problem with you )
3.str variable initialization


So I am writting a sample programme which I think

#include<stdio.h>
typedef struct
{
char file;
int a;
int b;
int c;

} structure;


int func(structure **Ob ) ;



int main(int argc, char **argv )
{

int error;
structure abc,*str;
abc.file= 'a' ;
abc.a= 1 ;
abc.b =2 ;
abc.c =3 ;
str =&abc ;
error = func( &str);
printf("TEMP C is %d", abc.c) ;

return error;

}
int func(structure **Ob ) {
printf("TEMP a is %d", (**Ob).a ) ;
(**Ob).c = 1000 ;
}


I guess this may be helpful you to solve your problem

Abhishek
 
A

abhishekkabra

If your problem is exactly like what you have given in example
then

1. First your function defination is wrong . It should be taking
argument pointer to pointer to structure like **Ob
2.You only give function declaration So Complier assumes that there may
be any defination also ( but i guess this is not problem with you )
3.str variable initialization


So I am writting a sample programme which I think

#include<stdio.h>
typedef struct
{
char file;
int a;
int b;
int c;

} structure;


int func(structure **Ob ) ;



int main(int argc, char **argv )
{

int error;
structure abc,*str;
abc.file= 'a' ;
abc.a= 1 ;
abc.b =2 ;
abc.c =3 ;
str =&abc ;
error = func( &str);
printf("TEMP C is %d", abc.c) ;

return error;

}
int func(structure **Ob ) {
printf("TEMP a is %d", (**Ob).a ) ;
(**Ob).c = 1000 ;
}


I guess this may be helpful you to solve your problem

Abhishek
 
D

Default User

Priya said:
What is wrong in the below code,
I get the 2 error when i compile the prog... what is mean ??


error C2275: structure: illegal use of this type as an expression
error C2065: str: undeclared identifier

The error reports don't match the code. I suspect you didn't post what
you actually ran.
typedef struct
{
char file;
int a;
int b;
int c;



} structure;

The above is fine, from a syntax point. I strongly question a one
character variable named "file". I suspect you want a char buffer
there.
int func(structure *Ob,
char *fileName);

As is this, although I don't like that first parameter name.
int main(int argc, char **argv )
{

You don't use the args, so them leave out.
int error;
structure *str;

You have a pointer to a structure type, but haven't assigned any memory
to it. That's a disaster waiting to happen.
error = func(&str, "abc.txt");

The signature of func is looking for a pointer to a structure, so you
passed it the ADDRESS of a pointer to a structure. That's a pointer to
a pointer to structure.

When I compile it, I get the error I would expect:

error C2664: 'func' : cannot convert parameter 1 from 'structure ** '
to 'structure *' Types pointed to are unrelated

Change it to declaring a structure variable, not a pointer:

structure str;

return error;

Without knowing what func() does (you didn't include the definition),
this return is probably wrong. The only standard returns from main()
are 0, EXIT_SUCCESS, and EXIT_FAILURE.



Brian
 
R

Reghunath

structure *str;

In the above statement you declared a pointer to structure, and passing
its address to func. So you are trying to pass argument of type
structure ** to func.

I dont think any other problem exists with the code.
(func is not having a body, which may result in linker error)

regards,
Reghunath
 
J

John Bode

Priya said:
What is wrong in the below code,
I get the 2 error when i compile the prog... what is mean ??


error C2275: structure: illegal use of this type as an expression
error C2065: str: undeclared identifier


typedef struct
{
char file;
int a;
int b;
int c;



} structure;


int func(structure *Ob,
char *fileName);

int main(int argc, char **argv )
{


int error;
structure *str;


error = func(&str, "abc.txt");


return error;
}

Thanks
Priya

I don't get that error on this code under either gcc or MSVC 6.0; are
you sure this is the exact same code that causes the problem? Also,
when you copy the error message, could you also include the part of the
message that identifies the line that the error is on?

You do have a problem, though; you're passing str incorrectly to func.
You've defined func to take a pointer to structure, but you're passing
a pointer to pointer to structure. I *think* the problem is that you
declared str as a pointer to structure; change the declaration to

structure str;

to fix that problem.

I know this is just a toy program, but in the future please try to use
more meaningful names for your types.
 
D

Default User

Ken said:
Hi,

All errors were due to the definition of structure. Try this:

What error?
typedef struct _structure
{
char file;
int a;
int b;
int c;
} structure;


That tag is unnecessary unless a pointer to that type was needed within
the struct itself. Otherwise an anonymous struct will work fine.



Brian
 
D

Default User

I just compiles this code on gcc and it works absolutly fine without
any errors, just few warning messeges. which compiler are you using?


I'd check those warnings, it ain't fine at all. Wrong type passed to
the function.




Brian
 
D

Default User

Priya, I don't know which compiler you are using to compile this code,
here I'm using gcc and it is not giving any errors only one warning
that is

17: warning: passing arg 1 of `func' from incompatible pointer type

The problem is in function call " error = func(&str, "abc.txt"); "
correct it to " error = func(str, "abc.txt"); " removing &.
Now it is working fine.


Depends on how you define "fine". There's no memory associated with
str, and no definition for func().



Brian
 
D

Default User

Bob said:
error = func(str, "abc.txt");
-- not --
error = func(&str, "abc.txt");


I think not. That's undefined behavior if func() does anything with the
pointer. Maybe even just calling the function with an uninitialized
pointer.



Brian
 
D

Default User

Netocrat said:
For those who still haven't clued on, in this thread to date the only
genuine posters have been myself, Lawrence Kirby, David Resnick (you would
have been better advised taking Kenny McCormack's advice) and Suman.

Hey! I'm reasonably genuine. At least I try not to be too much of a
phony.
The troll posted and has since been merrily responding to itself under the
names: Priya Mishra, Yohji, (e-mail address removed), Ken, Seven Kast USA,
(e-mail address removed), Neeraj Gupta and Mehta Shailendrakumar.

Based on what?




Brian
 
N

Netocrat

Hey! I'm reasonably genuine. At least I try not to be too much of a
phony.

Oh, you pass muster Brian. :) Your post hadn't appeared at the time I
wrote.
Based on what?

Common sense.

They don't deserve any more attention than we've given them, but I'll
point out the signs this time in the hope that this information prevents
others from getting hoodwinked in future (btw I've been taken in too). The
following signs add up to "pack of trolls":

1) all Google postings bar Mehta

2) no posting history bar Suman. vsnadagouda has one previous post that
smells of troll, but he did spot the uninitialised pointer and there's a
slim chance he's not a troll.

3) promptness of responses (esp considering (2))

4) style of the original post (cf the more extreme "chelleppa" style)

5) the flurry of consecutive top-level posts from "chellappa", "newlang",
"Priya Mishra", "Sven Kast USA" and "rahul8143" are clearly all from an
individual or cooperating group. They have the same style; they occurred
consecutively and within a short time period; chellappa and newlang share
an IP address and subject matter; all posted multiple times in an obvious
attempt to annoy

6) trolls reply to themselves

7) naivety or irrelevance (eg Ken) / ignorance (only one spotted the
uninitialised pointer) / childishness (Sven)

At first glance Suman passes muster: he has a 6 month posting history in
c.l.c. and seems to say some relatively on-topic things. But when I
looked closer I found:

1) Google poster

2) many of his posts appear to have been carefully designed to be
just so incorrect that they require a response without being an obvious
bait

3) most of his responses occur in troll-initiated threads

4) some of his responses are best interpreted as a troll responding to
itself/a companion troll. eg. Responding to chellapa's "I want a
relationship with you" with "Who'd want that? ;)".

5) some other incongruous comments inconsistent with a genuine regular: eg
responding unnecessarily to Richard Bos with "Aye, aye! Sir!" in the
thread "abt time functions"

He's a troll playing as a regular by carefully not stepping too obviously
outside the bounds, but he's left enough clues to be spotted. Here's
another from the "Floatin point issues" thread:
And don't you reply to me asking me why I am supporting [the regulars] -
I have my own reasons, that (your) reasons cannot comprehend.

Those reasons of course being to ingratiate himself as a regular whilst
continuing to subtly troll.

There may be some who don't care (or don't have the time/desire to check)
whether the originator of a post is trolling or not; they may be satisfied
as long as any inaccuracies within the post get corrected.

On the other hand I think that feeding the trolls should be avoided as
much as possible since it only encourages them and wastes many resources.

Some may consider _me_ a troll for focusing attention on the issue - it is
after all off-topic. It's apparent to me though that considerable
resources in this newsgroup are being spent on responding to trolls, and
once you know the signs, it's so easy to spot them and ignore them. Not
100% accurately of course, but how about we adopt Kenny McCormack's
suggestion from another seemingly troll-initiated thread ("Is this correct?"):
Can we please make it part of the religion of this NG that when people
post questions like this, they must also provide why they want to know?

I.e., we seem to do a pretty good job of stomping on them for all the OT
stuff, can't we also stomp on them for posting silly things w/o any
rationale given?

A great idea that would mitigate a lot of the trolling. Other techniques
are possible - eg. some kind of unofficial moderation where likely
troll-posts are identified and responded to appropriately (these
identification and response procedures could become part of the newsgroup
FAQ).

This method could at the least treat history-less Google-using posters
whose subject matter is irrelevant or less than interesting as "guilty
until proven innocent".
 
S

Suman

Netocrat said:
Oh, you pass muster Brian. :) Your post hadn't appeared at the time I
wrote.


Common sense.

They don't deserve any more attention than we've given them, but I'll
point out the signs this time in the hope that this information prevents
others from getting hoodwinked in future (btw I've been taken in too). The
following signs add up to "pack of trolls":

1) all Google postings bar Mehta

2) no posting history bar Suman. vsnadagouda has one previous post that
smells of troll, but he did spot the uninitialised pointer and there's a
slim chance he's not a troll.

3) promptness of responses (esp considering (2))

4) style of the original post (cf the more extreme "chelleppa" style)

English is not the native language of all who come over here,
so you should not be expecting literary geniuses here. Some structure
is of course required, but that should not be the only criterion
to bar someone from posting.
5) the flurry of consecutive top-level posts from "chellappa", "newlang",
"Priya Mishra", "Sven Kast USA" and "rahul8143" are clearly all from an
individual or cooperating group. They have the same style; they occurred
consecutively and within a short time period; chellappa and newlang share
an IP address and subject matter; all posted multiple times in an obvious
attempt to annoy

6) trolls reply to themselves

If this is one such troll-post, why did you jump-in? Could've created
a new thread, which would have been more appropriate, knowing full-well
that you are not going to be POLNKed.
7) naivety or irrelevance (eg Ken) / ignorance (only one spotted the
uninitialised pointer) / childishness (Sven)

At first glance Suman passes muster: he has a 6 month posting history in
c.l.c. and seems to say some relatively on-topic things. But when I
looked closer I found:
I must say you might hate me, but you couldn't ignore me:) Could you?
1) Google poster

I didn't know it was an offence to post via Google. There definitely
are reasons for using Google, ease of availability/use being one such.
2) many of his posts appear to have been carefully designed to be
just so incorrect that they require a response without being an obvious
bait

No. Not in my knowledge.
3) most of his responses occur in troll-initiated threads

Depends on how you define trolls. Moreover, I try to get help from
clc and then chip-in as and when I can. I might be wrong, but not
trying won't help either. Will it?
4) some of his responses are best interpreted as a troll responding to
itself/a companion troll. eg. Responding to chellapa's "I want a
relationship with you" with "Who'd want that? ;)".

So some people are more equal than others. Humour is a luxury that I
cannot
afford. Right? There was another post, same thread, in a similar vein.
Any comments?
5) some other incongruous comments inconsistent with a genuine regular: eg
responding unnecessarily to Richard Bos with "Aye, aye! Sir!" in the
thread "abt time functions"

How is that incongruent? I thought it was courtesy to reply to
people who are helping you. And of course, I *also* did think
humour is not frowned upon here.
He's a troll playing as a regular by carefully not stepping too obviously
outside the bounds, but he's left enough clues to be spotted. Here's
another from the "Floatin point issues" thread:
And don't you reply to me asking me why I am supporting [the regulars] -
I have my own reasons, that (your) reasons cannot comprehend.

I cannot change the way I write. Not for you.
Those reasons of course being to ingratiate himself as a regular whilst
continuing to subtly troll.

No. You are plain wrong. I do have respect for people.
 
N

Netocrat

On Wed, 13 Jul 2005 22:07:03 -0700, Suman wrote:

I must say you might hate me, but you couldn't ignore me:) Could you?

That statement suggests that you would be glad to be un-ignorable and
hated which is consistent with trollish behaviour. Not a particularly
good way to defend yourself.

In any case I don't hate you. I find trollish behaviour to be foolish and
wasteful of a useful resource, and I judged your behaviour to be trollish.

Since you have bothered to defend yourself and haven't slunk off I'll
consider the possibility that I misjudged you. As I said, your behaviour
is not overtly trollish and at first glance I didn't judge you as one.
There's no point in arguing back-and-forth over the details - it's the
big picture that counts.

So we'll see. No offence either way, but if you are a troll, then either
find something more useful to do or use the group for the right reasons.

<snip>
 
M

Mark F. Haigh

Netocrat said:
You are one of the more knowledgeable experts of this group and your
resources are wasted on responding to trolls, which it pains me to say is
what you have been doing for the last five posts.

Do you really think Lawrence is not aware of that? Interesting threads
often come from the most unlikely origins, and are often posted not for
the benefit of the original poster, but for the benefit of other
readers.

"The time you enjoy wasting is not wasted time." - Bertrand Russell
For those who still haven't clued on, in this thread to date the only
genuine posters have been myself, Lawrence Kirby, David Resnick (you would
have been better advised taking Kenny McCormack's advice) and Suman.

The troll posted and has since been merrily responding to itself under the
names: Priya Mishra, Yohji, (e-mail address removed), Ken, Seven Kast USA,
(e-mail address removed), Neeraj Gupta and Mehta Shailendrakumar.

Trolls come and go. The provoking of this meta-discussion could be
considered a victory for them. Usual practice is to respond topically
or not at all.



Mark F. Haigh
(e-mail address removed)
 
S

Suman

Netocrat said:
On Wed, 13 Jul 2005 22:07:03 -0700, Suman wrote:

I have been following clc for one and a half years even before I dared
to post here. But I cannot (not that I would care to) prove that.
That statement suggests that you would be glad to be un-ignorable and
hated which is consistent with trollish behaviour. Not a particularly
good way to defend yourself.

You replied to the wrong question. I wouldn't have been tongue-in-cheek
when I am defending myself.
In any case I don't hate you.

I am relieved!
I find trollish behaviour to be foolish and
wasteful of a useful resource, and I judged your behaviour to be trollish.

Since you have bothered to defend yourself and haven't slunk off I'll
consider the possibility that I misjudged you. As I said, your behaviour
is not overtly trollish and at first glance I didn't judge you as one.
There's no point in arguing back-and-forth over the details - it's the
big picture that counts.

I did not start it. Did I?

It bothers me to see so many of my queries (of the previous post)
go unanswered. I can only propose, but of course the high
and almighty disposes.

Few things that need mention:
1) there's been a recent spurt in troll-ish postings. My bet is: the
posters' do not intend to be trolls, rather it is a lack of information

that haunts them.
2) another common problem is the language. I might have responded to
such *trollish* (as judged by their language) posts, because it is
easier
for me to understand (being used to hear such) what the poster means
than it might be for a native English speaker.
So we'll see. What?
No offence either way, but if you are a troll, then either
find something more useful to do or use the group for the right reasons.

<snip>
Regards,
Suman.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top