Jump to content
  • Advertisement
Sign in to follow this  
Makaan

[c++] labels

This topic is 3634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Basically i want a label in the function to be visible outside the function. Is there a way to make something like this: static void f() { // as static as the function can be some_label: // ... } void F() { // have access to the address of the label some_label _asm { mov eax, some_label; } } thanks , Makaan

Share this post


Link to post
Share on other sites
Advertisement
Why do you think you need the address? You are not allowed to jump straight into other functions, if that's what you want (the stack would be messed up).

Share this post


Link to post
Share on other sites
The "address of the label" is not a meaningful description. A label may not have an address, or it may have more than one. Source code does not map directly to machine code.

Share this post


Link to post
Share on other sites
Yeah it would probably help to know what you're trying to accomplish. Do you want to make a jump table, are you trying to implement self-modifying code, ...?

Cheers
-Scott

Share this post


Link to post
Share on other sites
yes , i know about the stack , i don't want to jump from outside the function , but from inside it , i just need to load all the addresses into a int var a[] , for example, and then jump in the function according to the array:
example:

int t = a[count++];
_asm{
mov eax , t;
jmp eax;
}
...
label1:// ...
return;
label2:// ...
return;

Share this post


Link to post
Share on other sites
Quote:
Original post by Makaan
Basically i want a label in the function to be visible outside the function

Quote:
Original post by Makaan
i don't want to jump from outside the function , but from inside it
Huh?

Share this post


Link to post
Share on other sites
Wouldn't it make more sense to have an array of pointers to functions? And why on earth do you want to use inline assembly for a function call?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by Makaan
Basically i want a label in the function to be visible outside the function

Quote:
Original post by Makaan
i don't want to jump from outside the function , but from inside it
Huh?


example:
int count =0;
int a[666];
static void run()
{
int t = a[count++];
_asm{
mov eax , t;
jmp eax;
}
label1:// ...
cout<<"1";
return;
label2:// ...
cout<<"2";
return;
}
where `a , 0<=i<=666` needs to contain the address of label1 or label2

Quote:
Original post by DevFred
Wouldn't it make more sense to have an array of pointers to functions? And why on earth do you want to use inline assembly for a function call?

no , because i need this to run very fast , pointer to functions are slower than a `switch` with more than 44 case labels

Share this post


Link to post
Share on other sites
Try to explain what you're trying to do rather than how you're trying to do it. Because from your description it seems all you want is a switch statement.

Share this post


Link to post
Share on other sites
But then why make a[] a global variable, rather than a static (const) variable within the function?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!