---
name: "__builtin_object_size"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/__builtin_object_size"
---

# \_\_builtin\_object\_size(3)

return the size of the given object

## NAME

**\_\_builtin\_object\_size** – return the size of the given object

## SYNOPSIS

*size\_t*\

**\_\_builtin\_object\_size**(*void \*ptr*, *int type*);

## DESCRIPTION

The **\_\_builtin\_object\_size**() function is a [clang(1)](/clang/1.md) and [gcc(1)](/gcc/1.md) built-in function that returns the size of the object referenced by *ptr* if known at compile time. If the *ptr* expression has any side effects, then they will not be evaluated.

## RETURN VALUES

If the size of the object is not known or the *ptr* expression has side effects, the **\_\_builtin\_object\_size**() function returns:

- (size\_t)-1

  for *type* 0 and 1.

- (size\_t)0

  for *type* 2 and 3.

If the size of the object is known, then the **\_\_builtin\_object\_size**() function returns the maximum size of all the objects that the compiler knows can be pointed to by *ptr* when *type* & 2 == 0, and the minimum size when *type* & 2 != 0.

## SEE ALSO

[clang(1)](/clang/1.md), [gcc(1)](/gcc/1.md), \_\_builtin\_return\_address(3), attribute(3), [ssp(3)](/ssp/3.md)

## HISTORY

The **\_\_builtin\_object\_size**() appeared in GCC 4.1.

## CAVEATS

This is a non-standard, compiler-specific extension.

Note that currently the object size calculation pass is only done at -O1 or above, meaning that this function always returns -1 when the optimizer is off.

There are some discussions about always doing the object size pass, but the issue is that without the optimization pass data sizes are not going to be correct.

For that reason code fortification (size-checked replacement functions) is currently disabled when optimization is off.
