strange functions binutils-2.21

B

Bill Cunningham

I am looking at the binutils API and some of there function look strange
to me. For one thing they don't seem to want to simply show the prototype of
the functions with their explaination. Here's a link and a few odd functions
maybe someone can help me with. I hope this isn't too OT.

http://sourceware.org/binutils/docs-2.21/bfd/index.html

typedef void (*bfd_error_handler_type) (const char *, ...);

What does that mean? There's a typedef void. And then
(*bfd_error_handler_type)... is that a cast? The parameter looks like to
take a variable argument list life printf. (const char *,...). What is this
function's return type?

Bill
 
I

Ian Collins

I am looking at the binutils API and some of there function look strange
to me. For one thing they don't seem to want to simply show the prototype of
the functions with their explaination. Here's a link and a few odd functions
maybe someone can help me with. I hope this isn't too OT.

http://sourceware.org/binutils/docs-2.21/bfd/index.html

typedef void (*bfd_error_handler_type) (const char *, ...);

What does that mean?

That you are either a) still trolling or b) yet to read a decent C book.
 
K

Keith Thompson

Bill Cunningham said:
I am looking at the binutils API and some of there function look strange
to me. For one thing they don't seem to want to simply show the prototype of
the functions with their explaination. Here's a link and a few odd functions
maybe someone can help me with. I hope this isn't too OT.

http://sourceware.org/binutils/docs-2.21/bfd/index.html

typedef void (*bfd_error_handler_type) (const char *, ...);

What does that mean? There's a typedef void. And then
(*bfd_error_handler_type)... is that a cast? The parameter looks like to
take a variable argument list life printf. (const char *,...). What is this
function's return type?

No, it's not a cast; yes, that is a variadic parameter list,
similar to printf's.

It declares bfd_error_handler_type as a typedef for a
pointer-to-function type.

I frankly do not expect you to be able to make any use of this information.
 
B

Bill Cunningham

Keith said:
I frankly do not expect you to be able to make any use of this
information.

I already know what some of this API does but these functions like
this...How would you call them? I don't think the sockets API has any
functions like that and except for rarer instances I for the most part know
what it's doing designing a socket.

"It declares bfd_error_handler_type as a typedef for a
pointer-to-function type."

So it sounds kind of like a generic function maybe if that's the right
word? Maybe like void * ? CAn you give me an example Keith on how to call
it?

Bill
 
B

Bill Cunningham

Instead of a pointer to a function a function to a pointer which is a
type?

Bill
 
S

Seebs

That you are either a) still trolling or b) yet to read a decent C book.

Objection! We can't disprove the theory that he read it and then forgot
everything from it.

And honestly, an API that uses function pointers like that is probably not
the right place for someone who regularly gets stuck on questions comparable
to "this program has mismatched braces, and the compiler says that's a syntax
error, so I tried converting all the header names to uppercase, and now it
gives me a different error".

-s
 
G

Gene

    I already know what some of this API does but these functions like
this...How would you call them? I don't think the sockets API has any
functions like that and except for rarer instances I for the most part know
what it's doing designing a socket.

"It declares bfd_error_handler_type as a typedef for a
pointer-to-function type."

    So it sounds kind of like a generic function maybe if that's the right
word? Maybe like void * ? CAn you give me an example Keith on how to call
it?

Bill

Hi Bill,

You'd write a function such as this:

#include <stdio.h>
#include <stdarg.h>

void error_handler(const char *message, ...)
{
va_list ap; // follow the variadic function protocol of stdarg.h
va_start(ap, message);
vfprintf(stderr, message, ap); // print to standard error
va_end(ap);
}

Now in later code you can kake a pointer to this function:

.....
{
bfd_error_handler_type handler;
char *instruction = "Danger, Danger!";

// For example assign the address of the function to handler:
handler = &error_handler;

// Could make decisions to assign different values to handler here.

// Make a call on the handler pointer like this:
(*handler)("Will Robinson: %s\n", instruction);

// But more likely you'll pass the handler to an API function that
// will use it to deal with internal errors. This is known as a
"callback."
api_call(&error_handler);

}
 
K

Keith Thompson

Bill Cunningham said:
I already know what some of this API does but these functions like
this...How would you call them? I don't think the sockets API has any
functions like that and except for rarer instances I for the most part know
what it's doing designing a socket.

"It declares bfd_error_handler_type as a typedef for a
pointer-to-function type."

So it sounds kind of like a generic function maybe if that's the right
word? Maybe like void * ? CAn you give me an example Keith on how to call
it?

No, there's nothing generic about it. When I wrote that it's a
typedef for a pointer-to-function type, I didn't mean that it's a
typedef for *any* pointer-to-function type. It's for one specific
type. I just didn't bother to go into more detail.

As always, you are in *way* over your head.

Yes, I can give you an example. No, I won't waste my time doing so.
 
B

Bill Cunningham

Gene said:
Hi Bill,

You'd write a function such as this:

#include <stdio.h>
#include <stdarg.h>

void error_handler(const char *message, ...)
{
va_list ap; // follow the variadic function protocol of stdarg.h
va_start(ap, message);
vfprintf(stderr, message, ap); // print to standard error
va_end(ap);
}

Now in later code you can kake a pointer to this function:

....
{
bfd_error_handler_type handler;
char *instruction = "Danger, Danger!";

// For example assign the address of the function to handler:
handler = &error_handler;

// Could make decisions to assign different values to handler here.

// Make a call on the handler pointer like this:
(*handler)("Will Robinson: %s\n", instruction);

// But more likely you'll pass the handler to an API function that
// will use it to deal with internal errors. This is known as a
"callback."
api_call(&error_handler);

}

I will study this. Callback. What's its purpose in code? I've never
quite seen anything like it in C.

Bill
 
B

Bill Cunningham

Gene said:
Hi Bill,

You'd write a function such as this:

#include <stdio.h>
#include <stdarg.h>

void error_handler(const char *message, ...)
{
va_list ap; // follow the variadic function protocol of stdarg.h
va_start(ap, message);
vfprintf(stderr, message, ap); // print to standard error
va_end(ap);
}

Now in later code you can kake a pointer to this function:

....
{
bfd_error_handler_type handler;
char *instruction = "Danger, Danger!";

// For example assign the address of the function to handler:
handler = &error_handler;

// Could make decisions to assign different values to handler here.

// Make a call on the handler pointer like this:
(*handler)("Will Robinson: %s\n", instruction);

// But more likely you'll pass the handler to an API function that
// will use it to deal with internal errors. This is known as a
"callback."
api_call(&error_handler);

}

I got pissed at kandr2 and put it up for quite some time now. But I must
admit it is very thorough and delves in quite deep a little too quickly for
me. I'm not even sure to be quite honest if it mentions callbacks because I
never got through it and haven't picked it up to look through it thoroughly
for awhile. I might check when I get time. I'm just an amatuer hobbyist with
aspirations. I think I can put a note in an ELF file at SH_NOTE. That's all
I want to do right now.

Bill

PS It's reall not kandr2's fault it's my learning curve.
 
B

Bill Cunningham

Keith said:
As always, you are in *way* over your head.

Yes, I can give you an example. No, I won't waste my time doing so.

Keith What do you suggest I do? I have learned a bit more about C with
unix socket programming. I have created working sockets. Should I just focus
again on kandr2?

Bill
 
K

Keith Thompson

Bill Cunningham said:
Keith What do you suggest I do? I have learned a bit more about C with
unix socket programming. I have created working sockets. Should I just focus
again on kandr2?

K&R2 is fairly dense, and tends to assume prior programming
experience. I know you've been doing this for a long time, but
your postings here are not evidence that you have the necessary
background.

As I've tried to tell you before, I don't think C is the best
language for you. It's very unforgiving of the kinds of errors and
misunderstandings to which you're prone. I've suggested Python as
an alternative; I'm not a Python expert, and there might well be
better languages.

If you insist on learning C, you should probably get a good tutorial
and work your way through it. Take as long as it takes. Don't look
at chapter 2 until you've mastered chapter 1, and so forth.

(All this assumes you're not a deliberate troll; I'm not expressing
an opinion on that question at this time.)
 
B

Barry Schwarz

Keith What do you suggest I do? I have learned a bit more about C with
unix socket programming. I have created working sockets.

Patently impossible. Post some code and prove me wrong.
 
B

BruceS

No, it's not a cast; yes, that is a variadic parameter list, similar to
printf's.

It declares bfd_error_handler_type as a typedef for a
pointer-to-function type.

I frankly do not expect you to be able to make any use of this
information.

OTOH, others who search the ng for related topics may very well make use
of it. I can only imagine how frustrating it must be to attempt to
respond rationally to Bill. Ian and Seebs made me laugh, but your
response seems to me to be a good use of the forum.
 

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
473,952
Messages
2,570,116
Members
46,705
Latest member
BufordPala

Latest Threads

Top