Git Product home page Git Product logo

Comments (2)

ewenmcneill avatar ewenmcneill commented on May 30, 2024

FWIW, apparently ch12/noop was an executable, and it seems to have been added in June 2022:

ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ git log noop
commit 6ebd519f5a691a2f4c7d9cfbdb2d3e708e9d9681 (HEAD -> 1st-edition, origin/HEAD, origin/1st-edition)
Author: Tim McNamara <[email protected]>
Date:   Thu Jun 30 22:10:49 2022 +1200

    ch12: add noop binary for completeness
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ 

Possibly that should have resolved this issue?

Ewen

from code.

ewenmcneill avatar ewenmcneill commented on May 30, 2024

Possibly that should have resolved this issue?

Actually in the release version of the book, section 12.7 has two examples referred to as:

rustc ch12/fn-ptr-demo-1.rs && ./fn-ptr-demo-1

and

rustc ch12/fn-ptr-demo-2.rs && ./fn-ptr-demo-2

which are Listing 12.9 and Listing 12.10 respectively. The source to those probably should be in this repository (neither is present, just the noop executable!).

I think the noop binary which was added corresponds to Listing 12.9 (ie fn-ptr-demo-1.rs) based on the output. But it's unclear why the binary was added, rather than the source. Especialy as the binary will, at best, only work on Linux.

Ewen

Listing 12.9 output compared with noop executable output
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ file noop
noop: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bd628d94abc0aaaa7da48da7fe1bca30a3d3fe78, for GNU/Linux 3.2.0, with debug_info, not stripped
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ ldd noop
	linux-vdso.so.1 (0x00007ffd43fe9000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3fab747000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3fab742000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3fab73d000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3fab515000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f3fab7b7000)
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ ./noop 
noop as usize: 0x5578c49d7780
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ cat fn-ptr-demo-1.rs 
fn noop() {}

fn main() {
    let fn_ptr = noop as usize;
    println!("noop as usize: 0x{:x}", fn_ptr);
}
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ rustc fn-ptr-demo-1.rs 
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ ./fn-ptr-demo-1 
noop as usize: 0x55f529136400
ewen@rustdev:~/misc/src/rust/rust-in-action/ch12$ 


from code.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.