Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
02-18-2011, 02:05 PM
|
#61
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541
|
One way to fix your code is to define function_t as such:
Code:
typedef struct function_t { function_TEMPLATE } function_t;
But I must ask... why in hell are you intentionally obfuscating the readability of the code with macro definitions? From a professional standpoint, it looks like crap. Don't get offended! It is merely my opinion, for which I am entitled to possess.
|
|
|
Click here to see the post LQ members have rated as the most helpful post in this thread.
|
02-18-2011, 02:11 PM
|
#62
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
Quote:
Originally Posted by dwhitney67
One way to fix your code is to define function_t as such:
Code:
typedef struct function_t { function_TEMPLATE } function_t;
|
Why is function_t mentioned twice? I don't want to make an instance of function_t, if that's what it does.
Quote:
Originally Posted by dwhitney67
But I must ask... why in hell are you intentionally obfuscating the readability of the code with macro definitions? From a professional standpoint, it looks like crap. Don't get offended! It is merely my opinion, for which I am entitled to possess.
|
That's the best way I know of to achieve polymorphism in C. The idea is that all the contents of object_t are at the beginning of function_t, that way you can have an object_t pointer and treat it like an object_t, even if it's actually pointing to a function_t.
Last edited by MTK358; 02-18-2011 at 02:13 PM.
|
|
|
02-19-2011, 08:41 AM
|
#63
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
I changed it like this:
Code:
#define function_TEMPLATE \
object_TEMPLATE \
array_t *param_names; \
env_t *env; \
object_t* (*call)(function_t*, array_t*);
struct function { function_TEMPLATE };
typedef struct function function_t;
It still doesn't work.
EDIT:
This is what it looks like after being run through the preprocessor:
Code:
struct function { object_type_t objtype; array_t *param_names; env_t *env; object_t* (*call)(function_t*, array_t*); };
typedef struct function function_t;
I see nothing wrong with it.
Last edited by MTK358; 02-19-2011 at 10:12 AM.
|
|
|
02-19-2011, 02:02 PM
|
#64
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,831
|
You need to put the typedef for function_t before it's first use:
Code:
typedef struct function function_t; /* this goes first! */
#define function_TEMPLATE \
object_TEMPLATE \
array_t *param_names; \
env_t *env; \
object_t* (*call)(function_t*, array_t*);
struct function { function_TEMPLATE };
Last edited by ntubski; 02-19-2011 at 02:03 PM.
Reason: grammar
|
|
|
02-19-2011, 03:07 PM
|
#65
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
That fixed that issue. I didn't notice that the definition for function_t included function_t.
But now there's another one:
Code:
node_function.h:11:5: error: expected specifier-qualifier-list before ‘node_t’
node_function.h:14:70: error: expected declaration specifiers or ‘...’ before ‘node_t’
Code:
#ifndef __NODE_FUNCTION_H_INCLUDE_GUARD
#define __NODE_FUNCTION_H_INCLUDE_GUARD
#include "function.h"
#include "object.h"
#include "ast.h"
typedef struct node_function node_function_t;
struct node_function {
function_TEMPLATE
node_t *node;
};
node_function_t* node_function_new(array_t *param_names, env_t *env, node_t *node);
#endif
This can't have te same problem because the definition does not include node_function_t. And what's a "specifier-qualifier-list"?
|
|
|
02-19-2011, 05:23 PM
|
#66
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,831
|
Where is the declaration for node_t?
|
|
|
02-19-2011, 05:38 PM
|
#67
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
In ast.h.
|
|
|
02-19-2011, 06:22 PM
|
#68
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,831
|
The error message suggests that the declaration for node_t is missing, it's impossible to say more without seeing the rest of the code.
|
|
|
02-19-2011, 07:01 PM
|
#69
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
ast.h:
Code:
#ifndef __AST_H_INCLUDE_GUARD__
#define __AST_H_INCLUDE_GUARD__
#include "object.h"
#include "env.h"
#include "number_type.h"
#include "string_type.h"
#include "boolean_type.h"
#include "c_function.h"
#include "node_function.h"
#include <setjmp.h>
#include <stdarg.h>
typedef enum {
NODETYPE_NUMBER,
//NODETYPE_FLOAT,
NODETYPE_STRING, // create String
NODETYPE_IF, // evaluate only if condition true/false
NODETYPE_WHILE, // loop while condition true
NODETYPE_DOWHILE, // loop while condition true, eval body at least once
NODETYPE_CALL, // call function
NODETYPE_MEMBER, // get member from env ('.' operator)
NODETYPE_ASSIGN, // assign value to lvalue ('=' operator)
NODETYPE_FUNC, // create anonymous function
NODETYPE_THIS,
NODETYPE_THROW,
NODETYPE_TRY,
NODETYPE_INSIDE,
NODETYPE_BOOLEAN,
NODETYPE_BLOCK,
NODETYPE_SCOPE,
} nodetype_t;
typedef struct node node_t;
struct node {
nodetype_t type;
int child_count;
node_t **children;
void *payload;
};
extern jmpbuf_t exception_jmpbuf;
extern object_t *exception_object;
node_t* node_new(nodetype_t type, char *payload, int child_count, ...);
object_t *create_exception_env(object_t *name, object_t *message);
void node_eval_throw_exception(object_t *e);
object_t* node_eval(node_t *node, env_t *env);
#endif
|
|
|
02-19-2011, 07:33 PM
|
#70
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,831
|
I can't reproduce the error with the bits you've posted so far. I did notice that you have jmpbuf_t instead of jmp_buf.
|
|
|
02-20-2011, 09:41 AM
|
#71
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
Code:
ast.c:143:30: error: incompatible types when assigning to type ‘jmp_buf’ from type ‘struct __jmp_buf_tag *’
ast.c:145:30: error: incompatible types when assigning to type ‘jmp_buf’ from type ‘struct __jmp_buf_tag *’
What does this mean? I read about it and heard that jmp_buf is actually an array, but why doesn't this work?
|
|
|
02-20-2011, 02:22 PM
|
#72
|
Senior Member
Registered: May 2005
Posts: 4,481
|
Quote:
Originally Posted by MTK358
Code:
ast.c:143:30: error: incompatible types when assigning to type ‘jmp_buf’ from type ‘struct __jmp_buf_tag *’
ast.c:145:30: error: incompatible types when assigning to type ‘jmp_buf’ from type ‘struct __jmp_buf_tag *’
What does this mean? I read about it and heard that jmp_buf is actually an array, but why doesn't this work?
|
Copy-paste your code, including declaration of 'jmp_buf' and of '__jmp_buf_tag'.
What are you trying to do ? To assign to the whole array and not to array element ?
|
|
|
02-20-2011, 02:35 PM
|
#73
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
I never mentioned "__jmp_buf_tag" anywhere in my code. All I'm doing is assigning a variable to another, both of type "jmp_buf".
Code:
extern jmp_buf exception_jmpbuf; ast.h, line 44
extern object_t *exception_object;
-----
#include "ast.h" ast.c, line 1
jmp_buf exception_jmpbuf;
object_t *exception_object;
<snip>
else if (type == NODETYPE_THROW) line 133
{
node_eval_throw_exception(node_eval(node->children[0], env));
}
else if (type == NODETYPE_TRY)
{
jmp_buf prev_jmpbuf = exception_jmpbuf;
if (setjmp(exception_jmpbuf) == 0) {
node_eval(node->children[0], env);
exception_jmpbuf = prev_jmpbuf; line 143
} else {
exception_jmpbuf = prev_jmpbuf; line 145
env_set(env, "exception", exception_object);
node_eval(node->children[1], env);
env_del(env, "exception");
exception_object = NULL;
}
return NULL;
}
Last edited by MTK358; 02-20-2011 at 02:39 PM.
|
|
|
02-20-2011, 03:43 PM
|
#74
|
Senior Member
Registered: May 2005
Posts: 4,481
|
Quote:
Originally Posted by MTK358
I never mentioned "__jmp_buf_tag" anywhere in my code. ...
|
Then probably it's a result of some macro substitution. You need to look at preprocessed code (gcc -E ....).
|
|
|
02-20-2011, 04:14 PM
|
#75
|
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Original Poster
|
it still says "jmp_buf" everywhere.
I think I heard that jmp_buf is a typedef to an array or something?
|
|
|
All times are GMT -5. The time now is 11:04 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|