__STDC_VERSION__ not defined in avr-gcc project?

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

 

I'm moving over from PetitFs to FatFS (as per thread https://www.avrfreaks.net/forum/failing-pfmount-using-petitfs-cannot-determine-why).

 

The first major hurdle I'm having is trying to get the whole package compiled due to the following. ff.h contains the typedefs for integer types used by FatFS; however, all the types throw compilation errors due to unknown type names, and searching my entire project including all dependencies, I cannot find __STDC_VERSION__ defined anywhere?

 

Do I have to provide this definition myself? I've searched the entire ffsample code, including makefiles - and nowhere is this defined, only tested. I'm clearly not expected _WIN32 to be defined, using the avr-gcc Toolchain inside AS7.

 

/* Integer types used for FatFs API */

#if defined(_WIN32)	/* Main development platform */
#define FF_INTDEF 2
#include <windows.h>
typedef unsigned __int64 QWORD;
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus)	/* C99 or later */
#else
#define FF_INTDEF 2
#include <stdint.h>
typedef unsigned int	UINT;	/* int must be 16-bit or 32-bit */
typedef unsigned char	BYTE;	/* char must be 8-bit */
typedef uint16_t		WORD;	/* 16-bit unsigned integer */
typedef uint32_t		DWORD;	/* 32-bit unsigned integer */
typedef uint64_t		QWORD;	/* 64-bit unsigned integer */
typedef WORD			WCHAR;	/* UTF-16 character type */
#else  	/* Earlier than C99 */
#define FF_INTDEF 1
typedef unsigned int	UINT;	/* int must be 16-bit or 32-bit */
typedef unsigned char	BYTE;	/* char must be 8-bit */
typedef unsigned short	WORD;	/* 16-bit unsigned integer */
typedef unsigned long	DWORD;	/* 32-bit unsigned integer */
typedef WORD			WCHAR;	/* UTF-16 character type */
#endif

 

This topic has a solution.
Last Edited: Wed. Mar 25, 2020 - 09:48 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


Things that start with two underscores generally belong to the compiler so I think you'll find this is auto defined at compile time. Try the -E -dM trick to check.

 

EDIT: now back at computer so:

 

Last Edited: Tue. Mar 24, 2020 - 04:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That code block looks wrong to me ... it certainly triggers a compilation error with the g++ I have at hand.

 

#if 
...
#elif
#else
...
#else
...
#endif
exit status 1
#else after #else

 

Would it not be easier to hack that .h file for now and worry about 'doing it properly' later ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks both,

That's exactly what I've done - I know I'm using gnu99 C so I've just commented out the other bits.

I will come back to it to fix however as I hate leaving bits lying around like this.

Last Edited: Tue. Mar 24, 2020 - 11:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I tend to add a keyword  that can be grep'd when I make changes that need to be "fixed" later.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tend to use ###.

 

In Eclipse, if you put TODO: in  comments, it automatically gathers them all together into a "To Do" list

 

Dunno if Atmel/Visual Studio has a similar feature? or VAssist ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Yes AS7 inherits the TODO thing from VS

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Yes AS7 inherits the TODO thing from VS

It does so with HACK also which I tend to use to differentiate from general to-dos.

Somewhere in preferences you can add to the list of keywords also if you wish to use any other keyword.

EDIT - Oops, just noticed you posted a link to the actual preference, awneil.

Last Edited: Tue. Mar 24, 2020 - 10:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Things that start with two underscores generally belong to the compiler so I think you'll find this is auto defined at compile time. Try the -E -dM trick to check.

 

EDIT: now back at computer so:

 

Running any avr-gcc command within command prompt for me returns only an unknown command error, I assume to be able to run this - you have to install the avr-gcc toolchain into Windows, rather than working within AS only?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

returns only an unknown command error

Is your PATH set to find them?

 

If not, entering the full path+filename should do it

 

Or CD to the folder where the .exe lives ...

 

In your Start menu, in the Atmel Studio 7 folder, you should have an 'Atmel Studio 7 Command Prompt'

 

 

That will start a command prompt with a corectly-configured environment.

 

EDIT

 

The Atmel Studio install doesn't, apparently, include grep - so you'd have to get that from elsewhere ...

 

EDIT 2

 

Or just do it the Windows way:

 

 

note the need for quotes on a path with spaces ...

 

frown

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Mar 24, 2020 - 11:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, this looks like it should do the trick. Will confirm tomorrow when back at the PC.

I was simply using a 'normal' Windows CMD Window, without any CD command to anything but default directory, somewhat naively in hindsight.

Edit - Just seen your 'EDIT 2' - will make sure I try both methods tomorrow to embed it in my head!

Thanks for your input!

Last Edited: Tue. Mar 24, 2020 - 11:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So, having learned something in the form of the -E -dM command set, I can see that as expected my STDC version is > 199901.

avr-gcc -E -dM - < NUL | find "STDC"
#define __STDC_HOSTED__ 1
#define __STDC_UTF_16__ 1
#define __GNUC_STDC_INLINE__ 1
#define __STDC_VERSION__ 201112L
#define __STDC_UTF_32__ 1
#define __STDC__ 1

Having sorted the #ifdef #else #else issue, code compiles fine now. Cheers!