PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > What should be the prototype of this function ? (noonie)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
What should be the prototype of this function ? (noonie)

Réponse
 
LinkBack Outils de la discussion
Vieux 17/10/2007, 10h24   #1
ianbrn@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut What should be the prototype of this function ? (noonie)

Hello,
I have a struct defined thus:

typedef struct myStruct
{
int j;
} myStruct;

I saw somewhere calls with the following syntax:
f1(&*a)

What should be the protype of f1 so that it will be correct and
so that compilation will succeed ?

I am talking about two cases:
In the first, we have the following definition:
myStruct a;

in the second, we have
myStruct* a;

Is it possible with both case to have a definition of f1() so that
f1(&*a) will be correct and pass compilation ?

Any ideas?

Ian

  Réponse avec citation
Vieux 17/10/2007, 10h37   #2
Nick Keighley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: What should be the prototype of this function ? (noonie)

On 17 Oct, 10:24, "ian...@gmail.com" <ian...@gmail.com> wrote:

> I have a struct defined thus:
>
> typedef struct myStruct
> {
> int j;
>
> } myStruct;
>
> I saw somewhere calls with the following syntax:
> f1(&*a)
>
> What should be the protype of f1 so that it will be correct and
> so that compilation will succeed ?
>
> I am talking about two cases:
> In the first, we have the following definition:
> myStruct a;
>
> in the second, we have
> myStruct* a;
>
> Is it possible with both case to have a definition of f1() so that
> f1(&*a) will be correct and pass compilation ?
>
> Any ideas?



this looks like homework to me...


--
Nick Keighley



  Réponse avec citation
Vieux 17/10/2007, 11h19   #3
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: What should be the prototype of this function ? (noonie)

Nick Keighley wrote:
> On 17 Oct, 10:24, "ian...@gmail.com" <ian...@gmail.com> wrote:
>
>> I have a struct defined thus:
>>
>> typedef struct myStruct
>> {
>> int j;
>>
>> } myStruct;
>>
>> I saw somewhere calls with the following syntax:
>> f1(&*a)


[To the OP] Really? Where? What do you think it will do?

> this looks like homework to me...


It looks like bovine excrement to me.
  Réponse avec citation
Vieux 17/10/2007, 11h27   #4
vipvipvipvip.ru@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: What should be the prototype of this function ? (noonie)

struct name { /* ... */ };

ret f(struct name *);

struct name obj1, *obj2, obj3[1], **obj4;
f(&obj);
f(obj2);
f(obj3);
f(*obj4);

Etc.

`&*p' == `&p[0]'

  Réponse avec citation
Vieux 19/10/2007, 17h58   #5
Barry Schwarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: What should be the prototype of this function ? (noonie)

On Wed, 17 Oct 2007 09:24:50 -0000, "ianbrn@gmail.com"
<ianbrn@gmail.com> wrote:

>Hello,
>I have a struct defined thus:
>
>typedef struct myStruct
>{
> int j;
>} myStruct;
>
>I saw somewhere calls with the following syntax:
>f1(&*a)


It would if we new what a was.

What do you think the effect of the combined & and * operators is? For
extra points, would it make a difference if the operators were
reversed? What is the only possible type the expression &*a (or *&a)
can have (on those occasions when it is a legal expression)?

>
>What should be the protype of f1 so that it will be correct and
>so that compilation will succeed ?


The prototype is not the problem.

>
>I am talking about two cases:
>In the first, we have the following definition:
>myStruct a;


What happens when you apply the * operator to a struct?

>
>in the second, we have
>myStruct* a;
>
>Is it possible with both case to have a definition of f1() so that
>f1(&*a) will be correct and pass compilation ?


While passing an incompatible type to a function possibly could be
"corrected" by changing the prototype, what makes you think a
prototype can magically correct a syntax error?

Again, what happens when you apply the * operator to a struct?

>
>Any ideas?


Yes. Make a note of the author who wrote the call to f1. Then make
sure you never again take anything written by him seriously.


Remove del for email
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h51.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11051 seconds with 13 queries