3
\$\begingroup\$

When I try to declare either a unsigned long long or a uint64_t the xc8 compiler throws the following warning:

    12: uint64_t overflow_time;
             ^ (374) missing basic type; int assumed (warning)
             ^ (314) ";" expected
                          ^ (374) missing basic type; int assumed (warning)

This eventually spirals into an error later in the compilation. Through some research I found that when using the default C90 standard the xc8 compiler doesn't support 64-bit datatypes.

The best solution I could find online was "Upgrade to XC8 2.05" - which I already had.

How can I get the compiler to allow me to use 64 bit datatypes?

\$\endgroup\$
  • 3
    \$\begingroup\$ Just don't use 64 bit numbers on the least code efficient CPU still manufactured. Never. If you for reasons unknown need 64 bit resolution, you picked the completely wrong MCU for the task. You are essentially asking how to fit an elephant inside a porcelain store. Just because it is theoretically possible by temporary removing some wall, that doesn't mean it is a good idea or something you should be doing. \$\endgroup\$ – Lundin Aug 20 '19 at 14:22
  • 3
    \$\begingroup\$ What in the world are you doing that calls for a 64-bit integer? That's a very big number!! You might be better off asking about achieving what you want to achieve with a smaller integer. \$\endgroup\$ – Scott Seidman Aug 20 '19 at 14:43
  • 2
    \$\begingroup\$ @Lundin, that's a strange stipulation. Practically any CPU can handle very large numbers absolutely fine if performance is not a problem, which OP didn't say was a concern. And large data on small or very low cost CPUs is very common. All depends on the requirements of the application, as with every design: cost, availability, performance, familiarity with tools, cost, commonality with other designs, cost. And cost, usually :-) \$\endgroup\$ – TonyM Aug 20 '19 at 20:50
  • 4
    \$\begingroup\$ @Lundin Doing some 64 bit addition on my PIC18F47K42 uses <4.5% of the data memory and <1.1% of the program memory... \$\endgroup\$ – Harry Beadle Aug 21 '19 at 9:45
  • 3
    \$\begingroup\$ @Lundin, OP's CPU can perform 64-bit addition fine. Or 1024-bit. You're inventing a performance/space problem to solve. The world uses mountains of 8-bit CPUs, some in high-volume, very low-cost applications. They forget MIPS/$, all about tiny $. (We've disagreed about this before and are getting nowhere here. Look wider, it's a far diverser market than just mainstream Europe/US supplier price lists.) \$\endgroup\$ – TonyM Aug 21 '19 at 21:33
11
\$\begingroup\$

64-bit datatypes are available to use but you must use the following flags when compiling:

--std=C99 --ext=cci

This makes the compiler use the C99 standard with the Common C Interface. With these compiler flags you will be able to use 64-bit integers.

However, it may require you to reformat your code as some C90 code will not play nicely with C99. It is worth searching through the Compiler Handbook for "CCI" too, as this also changes how you have to format your code (notably for interrupts).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.