Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Elegance and truth are inversely related. -- Becker's Razor


devel / comp.lang.c / function pointers

SubjectAuthor
* function pointersHul Tytus
+* Re: function pointersStefan Ram
|`- Re: function pointersHul Tytus
+* Re: function pointersTim Rentsch
|`- Re: function pointersHul Tytus
+* Re: function pointersBart
|`- Re: function pointersHul Tytus
`- Re: function pointersDavid Brown

1
function pointers

<s8atrj$jip$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16587&group=comp.lang.c++#16587

  copy link   Newsgroups: comp.lang.c
 by: Hul Tytus - Sat, 22 May 2021 12:36 UTC

The code below generates "missing type declaration" errors. Anyone
know what form the type declaration for acodsch() should be?

Hul

/* ------------------------------------------------------------- */
struct atab {
char asm[4];
int (*opfnct)();
} asmtab[200];

(*)() /* <-- what goes here? */
acodsch(x)
int x;
{ return asmtab[x].opfnct;
}

Re: function pointers

<f-20210522140125@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16588&group=comp.lang.c++#16588

  copy link   Newsgroups: comp.lang.c
 by: Stefan Ram - Sat, 22 May 2021 13:02 UTC

Hul Tytus <ht@panix.com> writes:
> Anyone
>know what form the type declaration for acodsch() should be?

main.c

struct s { int ( *g )( void ); }a[ 1 ];
int( *f( int const n ))( void ){ return a[ n ].g; }
int main( void ){}

Re: function pointers

<86wnrqewod.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16589&group=comp.lang.c++#16589

  copy link   Newsgroups: comp.lang.c
 by: Tim Rentsch - Sat, 22 May 2021 13:16 UTC

Hul Tytus <ht@panix.com> writes:

> The code below generates "missing type declaration" errors. Anyone
> know what form the type declaration for acodsch() should be?
>
> Hul
>
> /* ------------------------------------------------------------- */
> struct atab {
> char asm[4];
> int (*opfnct)();
> } asmtab[200];
>
> (*)() /* <-- what goes here? */
> acodsch(x)
> int x;
> {
> return asmtab[x].opfnct;
> }

Here are two ways of declaring such a function:

struct atab {
char asem[4]; // probably better to avoid 'asm'
int (*opfnct)();
} asmtab[200];

int
(*acodsch_hard( int x ))(){
return asmtab[x].opfnct;
}

typedef int (*Pointer_to_int_function)();

Pointer_to_int_function
acodsch_easy( int x ){
return asmtab[x].opfnct;
}

(Comment: I recommend using function prototypes, as are shown
here, rather than K&R style function definitions.)

Re: function pointers

<iD7qI.326261$qHh9.313743@fx18.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16592&group=comp.lang.c++#16592

  copy link   Newsgroups: comp.lang.c
 by: Bart - Sat, 22 May 2021 13:25 UTC

On 22/05/2021 13:36, Hul Tytus wrote:
> The code below generates "missing type declaration" errors. Anyone
> know what form the type declaration for acodsch() should be?
>
> Hul
>
> /* ------------------------------------------------------------- */
> struct atab {
> char asm[4];
> int (*opfnct)();
> } asmtab[200];
>
> (*)() /* <-- what goes here? */
> acodsch(x)
> int x;
> {
> return asmtab[x].opfnct;
> }
>

It should match the declaration of opfnct, so try:

int (*acodsch(int x))()
{
....
}

I have to say I find C function pointer declarations incredibly
confusing. I initially had that 'int x' in that last pair of (), where
it ought to intuitively go, but I had to employ a tool to get it right.

Re: function pointers

<s8b8gt$71b$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16596&group=comp.lang.c++#16596

  copy link   Newsgroups: comp.lang.c
 by: Hul Tytus - Sat, 22 May 2021 15:38 UTC

Stefan - many thanks. Your example worked well.

Hul

Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> Hul Tytus <ht@panix.com> writes:
> > Anyone
> >know what form the type declaration for acodsch() should be?

> main.c

> struct s { int ( *g )( void ); }a[ 1 ];
> int( *f( int const n ))( void ){ return a[ n ].g; }
> int main( void ){}

Re: function pointers

<s8b8kc$71b$2@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16597&group=comp.lang.c++#16597

  copy link   Newsgroups: comp.lang.c
 by: Hul Tytus - Sat, 22 May 2021 15:39 UTC

Tim - thanks. That's what was needed.

Hul

Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Hul Tytus <ht@panix.com> writes:

> > The code below generates "missing type declaration" errors. Anyone
> > know what form the type declaration for acodsch() should be?
> >
> > Hul
> >
> > /* ------------------------------------------------------------- */
> > struct atab {
> > char asm[4];
> > int (*opfnct)();
> > } asmtab[200];
> >
> > (*)() /* <-- what goes here? */
> > acodsch(x)
> > int x;
> > {
> > return asmtab[x].opfnct;
> > }

> Here are two ways of declaring such a function:

> struct atab {
> char asem[4]; // probably better to avoid 'asm'
> int (*opfnct)();
> } asmtab[200];

> int
> (*acodsch_hard( int x ))(){
> return asmtab[x].opfnct;
> }

> typedef int (*Pointer_to_int_function)();

> Pointer_to_int_function
> acodsch_easy( int x ){
> return asmtab[x].opfnct;
> }

> (Comment: I recommend using function prototypes, as are shown
> here, rather than K&R style function definitions.)

Re: function pointers

<s8b8ni$71b$3@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16598&group=comp.lang.c++#16598

  copy link   Newsgroups: comp.lang.c
 by: Hul Tytus - Sat, 22 May 2021 15:41 UTC

Thanks Bart.

Hul

Bart <bc@freeuk.com> wrote:
> On 22/05/2021 13:36, Hul Tytus wrote:
> > The code below generates "missing type declaration" errors. Anyone
> > know what form the type declaration for acodsch() should be?
> >
> > Hul
> >
> > /* ------------------------------------------------------------- */
> > struct atab {
> > char asm[4];
> > int (*opfnct)();
> > } asmtab[200];
> >
> > (*)() /* <-- what goes here? */
> > acodsch(x)
> > int x;
> > {
> > return asmtab[x].opfnct;
> > }
> >

> It should match the declaration of opfnct, so try:

> int (*acodsch(int x))()
> {
> ....
> }

> I have to say I find C function pointer declarations incredibly
> confusing. I initially had that 'int x' in that last pair of (), where
> it ought to intuitively go, but I had to employ a tool to get it right.

Re: function pointers

<s8bj44$5ep$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16599&group=comp.lang.c++#16599

  copy link   Newsgroups: comp.lang.c
 by: David Brown - Sat, 22 May 2021 18:38 UTC

On 22/05/2021 14:36, Hul Tytus wrote:
> The code below generates "missing type declaration" errors. Anyone
> know what form the type declaration for acodsch() should be?
>
> Hul
>
> /* ------------------------------------------------------------- */
> struct atab {
> char asm[4];
> int (*opfnct)();

Don't leave the parameter types missing, unless you /really/ mean a
function with non-specified parameters. If the function should be
called without parameters, declare it "int (*opfcnt)(void);". If it
should be called with parameters, give the types such as "int".

Non-prototype function declarations (like that one, and the K&R style
for "acodsch" below) have been outdated for 30+ years, obsolescent for
20+ years, and will (AFAIUI) be removed from the language in the next C
standard.

So to modify Tim's solution slightly:

typedef int (*opfn)(int);

struct atab {
char asem[4];
opfn opfnct;
} asmtab[200];

opfn acodsch(int x) {
return asmtab[c].opfnct;
}

> } asmtab[200];
>
> (*)() /* <-- what goes here? */
> acodsch(x)
> int x;
> {
> return asmtab[x].opfnct;
> }
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor