0

Could someone please tell me how to solve this problem described in the title? I've searched for a long time but still not found a solution yet.

Update: I'm using window system

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
o o
  • 145
  • 6
  • Can you show a [mcve] where you use it? May want to take a look at some documentation to make sure you have the right defines and such: https://linux.die.net/man/2/sbrk – Retired Ninja Jul 12 '21 at 11:49
  • 1
    The `sbrk` function isn't actually in the POSIX standard. It's a legacy function whose use is generally discouraged. However, depending on your system there might be special feature macros that needs to be enabled or set to special values for it to be declared. Please [edit] your question to tell us the operating system you're targeting. – Some programmer dude Jul 12 '21 at 11:49
  • @Someprogrammerdude I'm using Window system – o o Jul 12 '21 at 11:53
  • 4
    You do know that `sbrk` was a **Unix** function? It has never been available for Windows, unless in emulated environments. What are you really trying to do? What is your actual and underlying problem you want to solve with the `sbrk` function?' – Some programmer dude Jul 12 '21 at 11:54
  • @Someprogrammerdude I'm trying to run the K&R's implementation of malloc in which ```sbrk``` is being used. – o o Jul 12 '21 at 12:00
  • Even in UNIX environments, `sbrk()` may be only conditionally defined, depending on feature-test macros. Including `unistd.h` (the first time) without meeting the relevant feature-test macro requirements will result in it not declaring `sbrk()`. You would need to check the documentation for your implementation for details. – John Bollinger Jul 12 '21 at 12:00
  • 1
    Considering that book was written for a UNIX environment (the first edition long before even DOS existed) you might want to consider installing a UNIX-like environment for experimenting. For example [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/install-win10), or install a virtual machine like VirtualBox and install a Linux system on it. You still need to enable [feature test macros](https://man7.org/linux/man-pages/man7/feature_test_macros.7.html) before including `` for [`sbrk`](https://man7.org/linux/man-pages/man2/brk.2.html) to be declared. – Some programmer dude Jul 12 '21 at 12:12
  • 1
    Maybe you should read [this article about sbrk](https://en.wikipedia.org/wiki/Sbrk)? If you plan to write your own `malloc`/`free` for an native application running under Windows operating system, you should use Windows own system calls related to [memory management](https://learn.microsoft.com/en-us/windows/win32/memory/memory-management-functions). – fpiette Jul 12 '21 at 13:05

0 Answers0