You create a float in C on ARM the same way you do on any other target: declare a float object, give it a value with an f suffix, and let the compiler choose the right representation and registers. What actually changes on ARM is everything underneath that one line — the IEEE-754 single-precision layout, the hard-float vs. soft-float calling convention, register placement (s0–s31 vs. r0–r3), and the FPU flags you must pass to the compiler and linker so the function call, not just the declaration, behaves correctly.
The key condition is this: on a non-x86 target like ARM, "making a float" is partly a source-code act and partly a build-configuration act. If you only do the first, you can get a program that compiles cleanly, links, and then silently fails or drops to slow software emulation. This article walks through declaring floats, understanding the bit layout, controlling the ABI with hard-float, and verifying that your floats are actually using the FPU.
The Source-Level Part: Declaring and Using a float
Before any architecture nuance, the C language rules are the same everywhere. A float is typically a 32-bit single-precision value on ARM targets, and the suffix matters.
The trailing f forces the literal to be a float. Without it, 3.14 is a double, and assigning it to a float triggers an implicit narrowing conversion. The compiler will usually warn, and on a hard-float ARM target it may insert a vcvt conversion instruction. That is not wrong, but it is often not what embedded developers intend. Use the f suffix unless you specifically need a double.
Qualifiers behave as expected:
const float places the value in read-only memory when it's a global or static. volatile float prevents the compiler from caching the value in a register — useful for memory-mapped hardware, dangerous for math performance. static float gives internal linkage at file scope.
A quick, simple, verifiable program:
On a correctly configured ARM hard-float toolchain, this prints sum = 3.750000. If it prints garbage or fails at the ABI boundary, the problem is almost always build configuration, not the C. That is the theme we need to unpack.
The Bit-Level Part: What a float Actually Is
A 32-bit IEEE-754 single-precision float is laid out in three fields:
| Field | Bits | Purpose |
|---|---|---|
| Sign | 1 (bit 31) | 0 = positive, 1 = negative |
| Exponent | 8 (bits 30–23) | Biased by 127 |
| Fraction | 23 (bits 22–0) | Mantissa without the implicit leading 1 |
The value is (-1)^sign × 1.fraction × 2^(exponent-127) for normal numbers, with special handling for zero, subnormals, infinities, and NaN. This layout is identical on ARM, x86, and RISC-V — it's the IEEE-754 standard, not an ARM invention. ARM just multiplies and adds these values in its vector floating-point units rather than the x87 stack.
Why mention the layout at all? Because two common tasks require it: converting a float to a uint32 to inspect its bits (a classic "make a float" exercise in embedded interviews), and sending floats over a wire to another device.
The memcpy idiom is portable and avoids strict-aliasing undefined behavior. So f2bits(1.5f) returns 0x3FC00000: sign 0, exponent 0x7F (=127, so 2^0), fraction .5 packed as 0x400000. That breakdown is checkable by hand — useful when you need to assert a float's bits in a test.
On ARM specifically, the GCC builtins __builtin_bit_cast (C23 and newer compilers) or a union type both work, but the memcpy form is the safest across compiler versions. Integer and float registers are separate on ARM, so this bit-level conversion actually requires a trip through memory or an explicit vmov instruction — the compiler will emit that for you.
The Hard Part: ARM's Two Floating-Point ABIs
This is where "on ARM" genuinely matters. ARM processors have separate integer and floating-point register files in their hard-float profiles, and the calling convention decides where a float argument goes during a function call:
Soft-float (-mfloat-abi=soft): floats are passed in integer registers (r0–r3) and arithmetic is done in software. Slow, but works on any ARM core, including ones with no FPU. Softfp (-mfloat-abi=softfp): floats are passed in integer registers, but arithmetic uses the FPU. A compromise ABI. Hard-float (-mfloat-abi=hard): floats are passed in FPU registers (s0–s31 for single precision, d0–d15 for double on some profiles). Fastest, and the usual default for application processors.
The catch: you cannot mix hard-float and soft-float object files in the same call to a function that takes or returns a float. The compiler makes an ABI assumption, and if two translation units disagree, the float arrives in the wrong register — or in the wrong place entirely — and you get silent corruption.
A concrete failure: a library built with -mfloat-abi=hard is linked into an application compiled with -mfloat-abi=soft. Your code calls float scale(float x) from the library. Your caller pushes the argument in r0; the library expects it in s0. The library reads s0, which holds whatever stale value was there, and returns nonsense — or crashes. Nothing in the code looks wrong at the source level.
The standard fix is disciplined build configuration:
1: Decide the float ABI for the whole project (and every dependency). 2: Pass the same -mfloat-abi= value to both compile and link. 3: Pass -mfpu= matching the actual hardware (e.g., neon, vfpv4, fp-armv8). 4: Verify at link time that there is no mismatch.
A checklist for the whole toolchain build:
Compile flags: -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard (the -mfpu choice depends on your target). Linker flags: -mfloat-abi=hard again, since the linker validates and picks the proper startup/runtime. For a bare-metal project, ensure your linker script and startup code do not pull in a soft-float libgcc. With a toolchain like GCC's arm-none-eabi-gcc, check that the multilib selected by your flags is the hard-float one; arm-none-eabi-gcc -print-multi-directory reports which.
If you need to interoperate with soft-float code deliberately (rare), the only safe way is a hand-written trampoline that moves the argument from r0 into s0 and back. That's advanced, and I would not recommend it unless you have instrumentation to confirm the fix.
Verifying That Your Floats Actually Use the FPU
After the build, inspect the disassembly to confirm arithmetic is in the FPU, not the library. This is a success/failure check that catches the common misconfiguration.
If you see vadd.f32 s0, s0, s1 or vldr s0, [addr], your floats are using the hardware. If you instead see calls like bl aeabi_fadd or bl aeabi_fmul, you are in soft-float territory. On modern GCC this appears as a branch out to libgcc; a match in the disassembly is a direct stop-and-reconfigure signal.
To see the ABI choice explicitly, print the compiler's configuration:
If -mfloat-abi=hard and -mfpu=... are not what you expected, fix the build. That command's output is the ABI opinion your entire project inherits.
A second check: readelf -A on the final ELF lists architecture attributes, including Tag_ABI_VFP_args, which the linker stamps to record that this object uses the hard-float calling convention. Matching this tag across all objects in the link is a cheap way to prove the ABI is consistent.
Making a Float at Runtime: Conversions, Constants, and Edge Cases
"Making a float" can also mean constructing a value at runtime. On ARM there are a few practical details:
Integer-to-float conversion of a signed 32-bit value: (float)n uses the vcvt.f32.s32 instruction under hard-float, or the __aeabi_i2f helper under soft-float. For values above 2^24, the conversion loses integer precision because the mantissa is only 23 bits — a common source of bugs when accumulating large counts in float rather than double or an integer type. Integer division must occur before the cast if you want a float result: (float)a / (float)b gives a float, while (float)(a / b) truncates the integer division first. On ARM this is not a distinction the compiler will flag. Literal folding happens at compile time; a static const float initialized with a constant is stored in .rodata, usually loaded with vldr or vmov.
Rounding ultimately falls to the FPU. The VFP/NEON units support round-to-nearest-even by default; if you write your own numeric code, expect to double-check subnormal handling. On ARMv7-A with VFPv4 and later, subnormals are handled in hardware; on some earlier VFP variants with flush-to-zero (FPSCR.FZ) enabled, extremely small values round to zero, which can change your results. GCC exposes this only inconsistently — if exact subnormal behavior matters, test it rather than assume it.
The -ffast-math flag is worth flagging (pun intended): it lets the compiler reassociate and simplify floats, and on ARM it can change behavior around NaNs, signed zeros, and inf/nan propagation. Do not use it if your code depends on IEEE-754 edge cases. This is one of the few floating-point flags where the "obvious" optimization is dangerous.
A Note on Which ARM Cores Have an FPU
The article cannot treat "ARM architecture" as a single thing, because the FPU presence is profile-dependent:
ARMv7-A / ARMv8-A / ARMv9-A (application processors): FPU is standard; hard-float is typical for Linux userland and many RTOSes. ARMv7-M (Cortex-M3, M4, M7, M33, M55): VFP is optional; Cortex-M4F and M7 include a single-precision FPU (fpv4-sp-d16). On a Cortex-M3 or M0, there is no FPU, so -mfloat-abi=hard will not work — you must build soft-float, and "making a float" really means calling libgcc helpers. ARMv8-M with fp extension: some cores have it, some don't. Check the part's TRM; the compiler flag alone does not prove the hardware supports the instruction. ARMv8-A AArch64: the ABI is different again. In AArch64, floats are passed in v0–v7 (the SIMD/FP registers) by default; the -mfloat-abi flag is largely absent for AArch64, and the AAPCS64 calling convention applies. So "hard-float" vs. "soft-float" is a 32-bit ARM concern; 64-bit ARM is always "hard" with SIMD registers.
That distinction matters. If you move a project from 32-bit Armv8 (the arm in GCC) to AArch64 (the aarch64 in GCC), the code-level float declarations do not change, but the calling convention does — and mixing object files between the two is a link error at best, a silent miscompile at worst.
Putting It Together: A Build Recipe
Here is a complete, ordered recipe for the 32-bit ARM hard-float case. Adjust the -mfpu value for your exact part.
Prerequisites: a GCC ARM cross toolchain (arm-none-eabi-gcc or arm-linux-gnueabihf-gcc for Linux userland), a target definition matching the silicon, and the -print-multi-directory check available.
1: Pick the float ABI. Use -mfloat-abi=hard if the target has an FPU and every library you link will also be hard-float; otherwise softfp with a documented rationale. 2: Pick the FPU. On Cortex-M4F use -mfpu=fpv4-sp-d16; on Cortex-A use -mfpu=neon or -mfpu=fp-armv8 for ARMv8-A. Wrong values produce illegal-instruction traps on the actual hardware. 3: Pass these flags to both compile and link commands, and mirror them in your CMake CMAKE_C_FLAGS and CMAKE_EXE_LINKER_FLAGS. 4: Confirm the multilib: arm-none-eabi-gcc -mfloat-abi=hard -mfpu=fpv4-sp-d16 -print-multi-directory should print a hard-float libc path. 5: Build. If the linker fails with an ABI mismatch, that is the expected safe outcome — fix the offending object rather than suppress the warning. 6: Disassemble and grep for vadd, vmul, vldr, vstr. Presence of __aeabi_f* calls instead is a red flag. 7: Run a one-line float print test and compare against a known value (e.g., 1.5f + 2.25f prints 3.750000). This checks that startup code zeroed the FPU correctly and that the printf library can format a float — a %f that prints 0.000000 usually means the library lacks float support, not that the float is broken.
FAQ
Why does printf("%f") print 0.000000 on my ARM build? Many embedded C libraries (newlib-nano, for example) omit float formatting to save space. You may need --specs=n99c or the float-enabled spec, or use a library that supports %f. This is a library issue, not an ABI issue.
Can I mix hard-float and soft-float code? Not safely through a function call that passes or returns floats. If you must, wrap the boundary in an assembly trampoline that moves arguments between r0–r3 and s0–s15, and only after you can verify with objdump that the caller and callee agree.
Are float and double the same on ARM? No. Single-precision is 32 bits, double is 64 bits. Hard-float passes doubles in d0–d7/d16 depending on the variant, and soft-float treats them as eight-byte integer-register pairs. The declaration is the same on any platform; the register movement is not.
Does AArch64 use hard-float flags? Not in the 32-bit sense. AAPCS64 passes floating-point arguments in SIMD/FP registers by default; there is no -mfloat-abi=hard choice to make. Writing floats is identical; only the target triple (aarch64-...) and the calling convention differ.
How do I make a float literal without the f suffix behave? You don't want to. The suffix makes the literal a float; without it, it's a double. On a hard-float 32-bit target the compiler inserts a conversion (vcvt), and on soft-float it may call __aeabi_f2d. Use f deliberately.
Where can I inspect the actual ABI in an ELF? readelf -A file.o prints the Tag_ABI_VFP_args attribute. If a file's tag disagrees with your build, you have a mismatch.
Common Mistakes and How to Stop Them
If floats misbehave, the cause is usually one of these, in order of likelihood:
Mixed ABI in linked libraries. Symptom: wrong values only when crossing a function-call boundary into a library, or crashes. Reversible check: rebuild the library with the matching -mfloat-abi and -mfpu; check with readelf -A. Missing -mfpu on ARMv8-A or Cortex-M4F. Symptom: illegal-instruction trap when the first float op runs. Check with gcc -Q --help=target. Library output not installed for hard-float. Symptom: link fails, or soft-float libc is pulled in. Verify the multilib path with -print-multi-directory. Using -ffast-math where IEEE-754 semantics matter. Symptom: changing comparisons around NaN or signed zero. Remove the flag; do not chase the symptom. Integer precision loss above 2^24. Symptom: large counts that should be exact become off-by-one. Use double, int64_t, or scaled integers instead.
A word of caution: I would not "fix" an ABI symptom by copying an extra -mfloat-abi=soft flag into the linker. That changes the ABI of every float in the program and typically makes things worse. The safe path is to identify which translation unit has the wrong tag and rebuild it.
That is the whole picture: a float in C on ARM is a one-line declaration whose correctness depends on a coherent, uniform build configuration. Once the compiler flags and linked libraries agree, the IEEE-754 bits, the FPU instructions, and the runtime values line up, and your code behaves the same as on any IEEE-754 machine.