Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9063227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:56:24+00:00 2026-06-16T15:56:24+00:00

In chapter 6.2.1 of Mitchell’s book (Concepts in Programming Languages), it mentioned that: Type

  • 0

In chapter 6.2.1 of Mitchell’s book (Concepts in Programming Languages), it mentioned that:

Type Casts. Type casts allow a value of one type to be used as another type. In C in particular, an integer can be cast to a function, allowing a jump to a location that does not contain the correct form of instructions to be a C function.

so I was up to use this non-safety and doing something unusual
I tried something like this (pseudo-code):

int x = 0;
print "loop";
x();

to create an infinite loop. I tried by changing and testing, but I couldn’t cope with that.
How can I do something or everything else like these stuffs?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:56:25+00:00Added an answer on June 16, 2026 at 3:56 pm

    @Soroush, here’s an example that might help you better understand what’s going on behind the scenes:

    #include <stdio.h>
    
    int main(void)
    {
        printf("begin\n");
        printf("loop\n");
    
        // declare a function pointer
        int (*loopPtr)();
        // set the function pointer to the current function
        loopPtr = main;
        // skip over the first printf();
        loopPtr += 22;
        // call the new location
        loopPtr();
    }
    

    For me, it works on x86_64 when compiled with clang -O0 (well, it works until the stack is exhausted since this is infinite recursion and each function call chews through stack space).

    I determined the offset 22 by compiling, then disassembling and subtracting the address of the start of main() from the address of the second printf().

    First, I compiled it:

    clang -O0 test.c
    

    Then disassembled it:

    otool -tv a.out
    

    …which produced this output:

    [...]
    _main:
    0000000100000ee0    pushq   %rbp
    0000000100000ee1    movq    %rsp,%rbp
    0000000100000ee4    subq    $0x20,%rsp
    0000000100000ee8    leaq    0x00000073(%rip),%rdi
    0000000100000eef    movb    $0x00,%al
    0000000100000ef1    callq   0x100000f40
    0000000100000ef6    leaq    0x0000006c(%rip),%rdi
    0000000100000efd    movl    %eax,0xf4(%rbp)
    0000000100000f00    movb    $0x00,%al
    0000000100000f02    callq   0x100000f40
    [...]
    

    _main: indicates the entrypoint of the main() function, whose first address is 0x100000ee0. The first callq instruction corresponds with the first printf() call, which I want to skip, so I chose the address just after that: 0x100000ef6. 0x100000ef6 minus 0x100000ee0 is 22 decimal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read a chapter in a book (Seven languages in Seven Weeks by Bruce
In chapter eight (p189) of CLR Via C#, Jeffrey Richter states that: A Type
In the security chapter of The Django Book , it says that I must
Getting stuck on chapter 8: Type as many words as we want One word
SICP Chapter 3.5.3 http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5.3 In section Streams as signals , SICP gives an audio-visual
I refer to Chapter 12. Criteria in this manual. They nicely explain that: The
If Book aggregates Chapter which in turn aggregates Page, then what should be the
Chapter 6 Language of the C Standard defines all the different concepts, conversions, lexical
In chapter 3 of Practical Common Lisp book there's an example of a SQL-like
In Chapter 3 of Programming Scala , the author gives two examples of for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.