473,320 Members | 1,535 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,320 software developers and data experts.

'typedef' issue

Hello,

consider the following code snippet:

typedef int (read_proc_t)(char *page, char **start, off_t off,int count,
int *eof, void *data);

struct proc_dir_entry {
unsigned short low_ino;
unsigned short namelen;
...
read_proc_t *read_proc;
write_proc_t *write_proc;
...
}

struct proc_dir_entry *test_entry;

Suppose I succesfully initialized 'test_entry' (it's not NULL). Why can't
I declare the function like this:

test_entry->read_proc = test_proc_read;
static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)
{ ... }

I get an error: `test_proc_read' declared as function returning a
function"

I thought as I declared new type with typedef I can use it?

Thanks for explanations.

--
Best regards, Roman
Mar 27 '07 #1
7 1768
Roman Mashak <m...@corecom.co.krwrote:
>
consider the following code snippet:

typedef int (read_proc_t)(char *page, char **start, off_t off,int
count, int *eof, void *data);
This declares read_proc_t as having function type.
static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)
{ ... }
This declares (and defines) a function as returning a function.
I get an error: `test_proc_read' declared as function returning a
function"
There is no lambda calculus in C. A function cannot return a function.
A function can return a function pointer though...

static read_proc_t *test_proc_read(char *page, char **start, off_t
off, int count, int *eof, void *data)

Note the extra *.

--
Peter

Mar 27 '07 #2
Roman Mashak <mr*@corecom.co.krwrites:
typedef int (read_proc_t)(char *page, char **start, off_t off,int count,
int *eof, void *data);
....
static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)
read_proc_t is the type "function taking char *, char **, off_t,
int, int, and void * parameters and returning int". You're
trying to declare a function that returns that type. The
compiler is justifiably complaining.

Apparently you want to do this:
static read_proc_t test_proc_read { ... }
However, the C standard explicitly disallows a function
definition that gives the function's type as a typedef,
presumably so that the definition has to include parameter names.
--
Comp-sci PhD expected before end of 2007
Seeking industrial or academic position *outside California* in 2008
Mar 27 '07 #3
On Mon, 26 Mar 2007 19:49:49 -0700, Ben Pfaff <bl*@cs.stanford.eduwrote:
>typedef int (read_proc_t)(char *page, char **start, off_t off,int count,
int *eof, void *data);
...
>static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)

read_proc_t is the type "function taking char *, char **, off_t,
int, int, and void * parameters and returning int". You're
trying to declare a function that returns that type. The
compiler is justifiably complaining.
Then what's the point of declaring 'read_proc_t' if I can't use it?
>
Apparently you want to do this:
static read_proc_t test_proc_read { ... }
However, the C standard explicitly disallows a function
definition that gives the function's type as a typedef,
presumably so that the definition has to include parameter names.

--
Best regards, Roman
Mar 27 '07 #4
Roman Mashak <mr*@corecom.co.krwrites:
On Mon, 26 Mar 2007 19:49:49 -0700, Ben Pfaff <bl*@cs.stanford.eduwrote:
>>typedef int (read_proc_t)(char *page, char **start, off_t off,int count,
int *eof, void *data);
...
>>static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)

read_proc_t is the type "function taking char *, char **, off_t,
int, int, and void * parameters and returning int". You're
trying to declare a function that returns that type. The
compiler is justifiably complaining.

Then what's the point of declaring 'read_proc_t' if I can't use it?
You can use a pointer to read_proc_t as an object type, or you
can use it to declare (not define) a function.
--
Comp-sci PhD expected before end of 2007
Seeking industrial or academic position *outside California* in 2008
Mar 27 '07 #5
On Mon, 26 Mar 2007 21:28:00 -0700, Ben Pfaff <bl*@cs.stanford.eduwrote:
>>>static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)

read_proc_t is the type "function taking char *, char **, off_t,
int, int, and void * parameters and returning int". You're
trying to declare a function that returns that type. The
compiler is justifiably complaining.

Then what's the point of declaring 'read_proc_t' if I can't use it?

You can use a pointer to read_proc_t as an object type, or you
can use it to declare (not define) a function.
But function definition and declaration should match, otherwise compiler
will complain.

--
Best regards, Roman
Mar 27 '07 #6
On Mar 27, 5:41 am, Roman Mashak <m...@corecom.co.krwrote:
On Mon, 26 Mar 2007 21:28:00 -0700, Ben Pfaff <b...@cs.stanford.eduwrote:
>>static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)
>read_proc_t is the type "function taking char *, char **, off_t,
int, int, and void * parameters and returning int". You're
trying to declare a function that returns that type. The
compiler is justifiably complaining.
Then what's the point of declaring 'read_proc_t' if I can't use it?
You can use it...just not in the definition of the function.
For example, you can use it to describe a member
of a structure.
>
You can use a pointer to read_proc_t as an object type, or you
can use it to declare (not define) a function.

But function definition and declaration should match, otherwise compiler
will complain.
consider:

[tmp]$ cat a.c
#include "a.h"

int
main(void)
{
char *start="start";
int x;
return foo( "page", &start, 0, 0, &x, &x );
}
[tmp]$ cat a.h
#define _XOPEN_SOURCE /* for off_t */
#include <unistd.h>

typedef int (read_proc_t)(char *page, char **start, off_t off,int
count,
int *eof, void *data);

read_proc_t foo;
[tmp]$ cat foo.c

#define _XOPEN_SOURCE
#include <unistd.h>

int
foo(char *p, char **s, off_t o, int c, int e, void *d)
{
return 0;
}

Mar 27 '07 #7

"Roman Mashak" <mr*@corecom.co.krwrote in message
news:sl****************@ecb-test32.corecom.local...
On Mon, 26 Mar 2007 19:49:49 -0700, Ben Pfaff <bl*@cs.stanford.eduwrote:
>>typedef int (read_proc_t)(char *page, char **start, off_t off,int count,
int *eof, void *data);
...
>>static read_proc_t test_proc_read(char *page, char **start, off_t off
int count, int *eof, void *data)

read_proc_t is the type "function taking char *, char **, off_t,
int, int, and void * parameters and returning int". You're
trying to declare a function that returns that type. The
compiler is justifiably complaining.

Then what's the point of declaring 'read_proc_t' if I can't use it?
>>
Apparently you want to do this:
static read_proc_t test_proc_read { ... }
However, the C standard explicitly disallows a function
definition that gives the function's type as a typedef,
presumably so that the definition has to include parameter names.
You don't say how you really intend to use this, but I think you
probably want to define your function as:

int test_proc(char *page, char **start, off_t off int count,
int *eof, void *data)
{
...
}

then you CAN set
test_entry->read_proc = test_proc_read;

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing


Mar 27 '07 #8

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

Similar topics

5
by: Roger Leigh | last post by:
Although I've got over most of my template-related problems, I'm having trouble when I started to use default template parameters. For template type T, I've typedef'd this as object_type and then...
0
by: Imre | last post by:
I'm planning to create a macro-based property system (reflection, automatic serializing for properties, that kind of stuff). The system would involve writing some PROPERTY(propName) macros between...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
5
by: Alan Woodland | last post by:
Hi, I don't think I can't do this directly with standard C++, I've tried all the ways I could think of that make sense and then some. I was wondering if someone had a genius idea how I could...
15
by: sam_cit | last post by:
I noticed that what is being done by typedef can very much be done by macro, and i also think there must be a specific reason as to why typedef was introduced, what is the exact difference, and...
5
by: tissyrose | last post by:
Hi All, I am porting a very large application from VC++ 6.0 to VS 2005. There are many issues I am facing. One of them is I am getting an error "cannot access private typedef declared in...
13
by: miaohua1982 | last post by:
the code is as follows: #include <iostream> using namespace std; typedef double DOUBLE; class Screen { public: typedef int DOUBLE;
5
by: Paul J. Lucas | last post by:
Given: template<typename T,typename Uclass C { }; template<typename Ttypedef C<T,intC2; I get: test.cpp:2: error: template declaration of 'typedef' Are template typedefs still not...
3
by: aaragon | last post by:
Hello everyone, I'm trying to run some simple code but for some reason it doesn't work and I've been staring at it for a long time without a single clue of what's going on. This is what happens,...
1
by: CJ | last post by:
Hello friends, It seems to be quite common in libraries (e.g. GMP) to have typedefs like typedef struct { /* stuff */ } __type_struct; typedef __type_struct type_t;
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
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.