473,786 Members | 2,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Jump to address syntax

Hello all,
I have an example of working code under my eyes that goes as follow:

unsigned long address=0x40000 0;
(void (*)(void)addres s)();

It's supposed to jump start a kernel loaded at that address from a small
bootloader.

But my cross compiler chokes on the second line (89) and I must say I've
tried variations of the syntax without success:

TestGpio/TestGpio.c: In function 'main':
TestGpio/TestGpio.c:89: error: expected ')' before numeric constant
TestGpio/TestGpio.c:89: error: expected expression before ')' token

It would make more sense to me as:
((void *)address)();
TestGpio/TestGpio.c: In function 'main':
TestGpio/TestGpio.c:90: error: called object '4194304u' is not a function

Maybe this one ?:
((void *)(void)address )();
TestGpio/TestGpio.c: In function 'main':
TestGpio/TestGpio.c:90: error: void value not ignored as it ought to be

--
Guillaume Dargaud
http://www.gdargaud.net/
Jul 16 '08 #1
7 9659
On Jul 16, 6:44*am, "Guillaume Dargaud"
<use_the_form_o n_my_contact_p. ..@www.gdargaud .netwrote:
Hello all,
I have an example of working code under my eyes that goes as follow:

unsigned long address=0x40000 0;
(void (*)(void)addres s)();

It's supposed to jump start a kernel loaded at that address from a small
bootloader.

But my cross compiler chokes on the second line (89) and I must say I've
tried variations of the syntax without success:

TestGpio/TestGpio.c: In function 'main':
TestGpio/TestGpio.c:89: error: expected ')' before numeric constant
TestGpio/TestGpio.c:89: error: expected expression before ')' token

It would make more sense to me as:
((void *)address)();
TestGpio/TestGpio.c: In function 'main':
TestGpio/TestGpio.c:90: error: called object '4194304u' is not a function

Maybe this one ?:
((void *)(void)address )();
TestGpio/TestGpio.c: In function 'main':
TestGpio/TestGpio.c:90: error: void value not ignored as it ought to be
The syntax to cast address to a function pointer and then call it
would look like this:

((void (*)(void))addre ss)();

It might be clearer to do something like this though:

void (*fptr)(void) = (void (*)(void))addre ss;
fptr();

--
Robert Gamble
Jul 16 '08 #2
Guillaume Dargaud wrote:
Hello all,
I have an example of working code under my eyes that goes as follow:

unsigned long address=0x40000 0;
(void (*)(void)addres s)();
[...]
ITYM `((void (*)(void))addre ss)();'.

Usually I disapprove of smuggling pointer-ness into a
typedef'ed type, but I make an exception for function pointers
because a pointerized typedef seems to help readability:

typedef void (*VFptr)(void);
((VFptr)address )();

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 16 '08 #3
In article <g5**********@c cpntc8.in2p3.fr >,
>(void (*)(void)addres s)();
You're trying to cast address to type "void (*)(void)". So you put
that type in parentheses before the variable:

(void (*)(void))addre ss

and you want to call it; you'll need more parentheses to get the
grouping right:

((void (*)(void))addre ss)();

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Jul 16 '08 #4
Eric Sosman <es*****@ieee-dot-org.invalidwrit es:
Guillaume Dargaud wrote:
>Hello all,
I have an example of working code under my eyes that goes as follow:

unsigned long address=0x40000 0;
(void (*)(void)addres s)();
[...]

ITYM `((void (*)(void))addre ss)();'.

Usually I disapprove of smuggling pointer-ness into a
typedef'ed type, but I make an exception for function pointers
because a pointerized typedef seems to help readability:

typedef void (*VFptr)(void);
((VFptr)address )();
I used to make this same exception, but is

typedef void VFptr(void);
((VFptr *)address)();

really any less readable?

(I think I got in to the habit because some pre-standard C compilers
refused to typedef a function type. I can't find any evidence for now
except a sense memory of surprise when I discovered that it is
standardised. Am I misremembering? )

--
Ben.
Jul 16 '08 #5
>typedef void (*VFptr)(void);
>((VFptr)addres s)();
or
typedef void VFptr(void);
((VFptr *)address)();
Thanks, yes those two forms are a lot clearer.
--
Guillaume Dargaud
http://www.gdargaud.net/
Jul 17 '08 #6
Guillaume Dargaud wrote:
typedef void (*VFptr)(void);
((VFptr)address )();

or
typedef void VFptr(void);
((VFptr *)address)();
This reads as a pointer to a function pointer. I'd prefer...

typedef void VFunc(void);
((VFunc *)address)();
>
Thanks, yes those two forms are a lot clearer.
In cases where you're calling the function often, it's clearer still
to transfer the casts to the declaration, or hide it in a function
macro...

#define frobnisticate() ((VFunc *) 0x400000)
or
VFunc *frobnisticate = (VFunc *) 0x400000;

frobnisticate() ;

--
Peter
Jul 17 '08 #7
Peter Nilsson <ai***@acay.com .auwrites:
Guillaume Dargaud wrote:
typedef void (*VFptr)(void);
((VFptr)address )();

or
typedef void VFptr(void);
((VFptr *)address)();

This reads as a pointer to a function pointer. I'd prefer...

typedef void VFunc(void);
((VFunc *)address)();
Yes so would I :-) That was not Guillaume Dargaud's fault -- when I
flipped the * from the typedef to the cast I kept the name to show the
symmetry but it would have been wiser to change the name at the same
time.

--
Ben.
Jul 17 '08 #8

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

Similar topics

7
2679
by: monomaniac21 | last post by:
Hi guys! Can anyone tell me how you can perform validation on a string variable in PHP so that you can check if a specific character is contained within the string. The reason for this is i am trying to create a form for a site i am making and i want to validate the user's input for the email address field, by ensuring it contains the '@' character. Cheers.
27
2251
by: Adam Warner | last post by:
Hi all, In the code snippet below I successfully determine the address of val1:* struct o val1=l_SYM_2B(&a).o; print_aesthetic(&val1); The structure o is heavyweight. I understand (hopefully correctly) that (barring compiler optimisations) C will shallow copy the structure into val1.
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9961
tracyyun
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...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
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...
0
5397
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...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
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...

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.