What's wrong about this:
22: static void (*)(void) instruction_tab le[] = {
jnz,
halt,
mv,
add,
mul,
mv_reg,
add_reg,
mul_reg,
pop,
push,
};
The compiler doesn't complain about wrong types of the functions, it says:
interpreter.c:2 2: syntax error before `)'
interpreter.c: In function `execute_instru ction':
interpreter.c:6 6: `instruction_ta ble' undeclared (first use in this function)
interpreter.c:6 6: (Each undeclared identifier is reported only once
interpreter.c:6 6: for each function it appears in.)
Thanks a lot
damian 5 2247
damian birchler <da************ *@bluewin.ch> scribbled the following: What's wrong about this:
22: static void (*)(void) instruction_tab le[] = { jnz, halt, mv, add, mul, mv_reg, add_reg, mul_reg, pop, push, };
The compiler doesn't complain about wrong types of the functions, it says:
interpreter.c:2 2: syntax error before `)' interpreter.c: In function `execute_instru ction': interpreter.c:6 6: `instruction_ta ble' undeclared (first use in this function) interpreter.c:6 6: (Each undeclared identifier is reported only once interpreter.c:6 6: for each function it appears in.)
The error is most likely in the function execute_instruc tion, not in the
above declaration. Please post the code to execute_instruc tion.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"There's no business like slow business."
- Tailgunner
damian birchler wrote: What's wrong about this:
22: static void (*)(void) instruction_tab le[] = {
[...] The compiler doesn't complain about wrong types of the functions, it says:
[...]
"instruction_ta ble" is the array of pointers. Therefore, you need:
static void (*instruction_t able[])(void) = ...
Or, as I prefer to do:
typedef void (*VoidFunc)(voi d);
static VoidFunc instruction_tab le[] = ...
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <Th************ *@gmail.com>
On Wed, 20 Oct 2004 11:45:43 -0700, damian birchler wrote: What's wrong about this:
22: static void (*)(void) instruction_tab le[] = { jnz, halt, mv, add, mul, mv_reg, add_reg, mul_reg, pop, push, };
The compiler doesn't complain about wrong types of the functions, it says:
interpreter.c:2 2: syntax error before `)' interpreter.c: In function `execute_instru ction': interpreter.c:6 6: `instruction_ta ble' undeclared (first use in this function) interpreter.c:6 6: (Each undeclared identifier is reported only once interpreter.c:6 6: for each function it appears in.)
Thanks a lot
Did you mean
static void *(*instruction_ table[])(void) = { ... }
?
In article <29************ **************@ posting.google. com>,
damian birchler <da************ *@bluewin.ch> wrote: What's wrong about this:
22: static void (*)(void) instruction_tab le[] = {
<snip>
The compiler doesn't complain about wrong types of the functions, it says:
interpreter.c: 22: syntax error before `)'
You have a syntax error.
Quoth cdecl:
cdecl> declare instruction_tab le as array of pointer to function (void) returning void
void (*instruction_t able[])(void )
So I think you might have wanted to say:
static void (*instruction_t able[])(void) = {
'Tmight also be worth using a typedef to make things a bit simpler:
typedef void (*instruction_f unc_ptr)(void);
static instruction_fun c_ptr instruction_tab le[] = {/*stuff*/};
interpreter. c: In function `execute_instru ction': interpreter.c: 66: `instruction_ta ble' undeclared (first use in this function) interpreter.c: 66: (Each undeclared identifier is reported only once interpreter.c: 66: for each function it appears in.)
The compiler attempted to recover from the syntax error so it could warn
you about other things, but this particular error is bogus, because it
depends on the part that the compiler skipped doing the error recovery
in the declaration.
dave
--
Dave Vandervies dj******@csclub .uwaterloo.ca
But they're not strings. Not being strings doesn't stop them being useful.
After all, ints aren't strings, yet they are very useful indeed!
--Richard Heathfield in comp.lang.c
damian birchler wrote: What's wrong about this:
22: static void (*)(void) instruction_tab le[] = { jnz, halt, mv, add, mul, mv_reg, add_reg, mul_reg, pop, push, };
The compiler doesn't complain about wrong types of the functions, it says:
interpreter.c:2 2: syntax error before `)' interpreter.c: In function `execute_instru ction': interpreter.c:6 6: `instruction_ta ble' undeclared (first use in this function) interpreter.c:6 6: (Each undeclared identifier is reported only once interpreter.c:6 6: for each function it appears in.)
Thanks a lot damian
Here is something that works
void jnz(void);void halt(void);void mv(void);void add(void);
void mul(void);void mv_reg(void);vo id add_reg(void); void mul_reg(void);
void pop(void);void push(void);
typedef void (*voidfn)(void) ;
static voidfn instruction_tab le[] = {
jnz,
halt,
mv,
add,
mul,
mv_reg,
add_reg,
mul_reg,
pop,
push,
};
C can be horrible, and arrays of function pointers belong to these
things that are unnecesarily difficult in the language. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: kohvirus |
last post by:
Well after embaressing myself and posting in the wrong fourm, I found
my way to the right one and I'm hoping to seek some help. This is the
program without any modifications that I am making recently (because
I'll most likely make it blow up moreso).
I'm currently trying to write a program with an array but for the life
of me I can't seem to get the right syntax for the array. Here is the
program as follows:
#include <iostream>
|
by: Gerald |
last post by:
I have a problem with an array of pointers.
In a program I'm writing, I have to read a file, containing thousands
of short lines. The content of another file will be compared against
each line later on. Before that happens there has been a problem that
causes a crash of the program.
This is a little program "test.exe" I wrote to test what happens.
compiler: mingw 3.1.01 for win32 command line
|
by: fix |
last post by:
Hi all,
I feel unclear about what my code is doing, although it works but I am
not sure if there is any possible bug, please help me to verify it.
This is a trie node (just similar to tree nodes) struct, I am storing an
array of 27 pointers and a void pointer that can point to anything.
typedef struct trieNode
{
struct trieNode *children; // The children nodes
void *obj; // The object stored
} TrieNode;
|
by: bsder |
last post by:
Hi,
Can anyone please tell me how to calculate the size of the following
4-dimensional array, and now to use qsort for sorting on this array?
double sp = { 4.0, 5.0, 6.0 };
double spa = {
{ 4.0, 2.0 },
{ 5.0, 8.0 },
{ 6.0, 6.0 },
|
by: natkw1 |
last post by:
Hi,
I'm attempting to understand the use of pointers(at least grasp how
pointers work). I've read the FAQ on
http://www.eskimo.com/~scs/C-faq/s6.html on pointers and arrays but I'm
still a bit lost.
I written the following code to try to understand it but it's not
working:
| |
by: Geoff Cox |
last post by:
Hello,
Can I separately declare and initialize a string array? How and where
would I do it in the code below? It was created using Visual C++ 2005
Express Beta 2 ...
In C# I would have
private string myArray;
|
by: roguefeebo |
last post by:
I'm very new to programming so be gentle, :(
Essentially what I would like to do is to have a single function to be able to create a dynamic array of pointers to a struct so that I can have a modular menu system up and running. My menus will have several varying numbers of options. This is the first time I've worked with something like this and just can't get it worked out.
I've snipped a lot of unnecessary code to this smaller piece so...
|
by: M Turo |
last post by:
Hi,
I was wondering if anyone can help. I'm want to pre-load a 'table' of
function pointers that I can call using a its arrayed index, eg (non c
code example)
pFunc = func_A;
pFunc = func_B;
|
by: aruna.mysore |
last post by:
Hi all,
I have a specific problem passing a function pointer array as a
parameter to a function. I am trying to use a function which takes a
function pointer array as an argument. I am too sure about the syntax
of calling the same.
#include <stdio.h>
void fp1()
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |