2013-01-17 05:11 PM
what is this for
/** ****************************************************************************** * @file STM32vldiscovery.h * @author MCD Application Team * @version V1.0.0 * @date 09/13/2010 * @brief Header file for STM32vldiscovery.c module. ****************************************************************************** * @copy * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2> */ /* Define to prevent recursive inclusion -------------------------------------*/&sharpifndef __STM32F100_Dicovery_H
&sharpdefine __STM32F100_Dicovery_H //this one, is see this in every header... what is their function? &sharpifdef __cplusplus extern ''C'' { &sharpendif /* Includes ------------------------------------------------------------------*/ &sharpinclude ''STM32f10x.h'' /** @addtogroup Utilities * @{ */ /** @addtogroup STM32vldiscovery #new-question-=-new-thread #include-guard #include-guard #include-guard #learning-c
2013-01-17 05:38 PM
C++ is intolerant of redefinition, this prevents circular or repetitive #include's
ie you #include <stdio.h> other files you include also have a #include <stdio.h>, etc.2013-01-17 05:43 PM
so this means
#ifndef __STM32F100_Dicovery_H#define __STM32F100_Dicovery_H //if not defined define this include as __STM32f100_dicovery_H and use it for the one implementing it...?
2013-01-18 01:39 AM
In even more plain words:
It means that, if you have 3 files all calling same library, they will not include functions from that library 3 times, but will use linker to link functions to one existing compiled library source. This define tells compiler that if library was once compiled, it does not need to be recompiled again, but just linked to it. This also saves space as pointers are small compared to some large functions which can be in libraries.2013-01-18 03:14 AM
''if you have 3 files all calling same library''
No, that's wrong. This has nothing to do with the header being included by multiple different source files (or, more strictly, ''compilation units'') What this prevents against is the file being included in the
same
compilation unit multiple times. It is a standard, widely-used practice in 'C' programming - commonly known as an ''Include Guard''.2013-01-18 03:25 AM
Example.
Say we have a .c file which includes this header 3 times:# include STM32vldiscovery.h
# include STM32vldiscovery.h
# include
STM32vldiscovery.h
What the compiler will actually see is:
// From 1st #include:
#ifndef __STM32F100_Dicovery_H// this is not defined - so the compiler ''sees'' the rest of the file
#define __STM32F100_Dicovery_H // now we define it
// the compiler ''sees'' the rest of the file...
#endif
// From 2nd #include:
#ifndef __STM32F100_Dicovery_H // IS now defined - so compiler ignores the rest of the file
#endif
// From 3rd #include:
#ifndef __STM32F100_Dicovery_H // IS still defined - so compiler again ignores rest of file
#endif
You wouldn't normally directly #include the same header like that - but, as already noted, it might happen as a result of one header file #including another...
Note that names with leading underscores should be reserved for use by the compiler - so, strictly, ST (like many others) are being naughty in their naming here.2013-01-18 03:35 AM
Just to emphasise that this is a standard practice - nothing specifically to do with STM32, or ST, or embedded...
2013-01-18 03:54 AM
Starting both with C and Cortex M3 at the same time seems to make a good recipe for disappointments.
One should at least master the ''hello world'' with a PC compiler ...2013-01-18 04:13 AM
''One should at least master the ''hello world'' with a PC compiler ...''
I (among others) think that is a very good suggestion!
Here's my list of some suggested resources for learning C:
2013-01-18 05:27 AM
Ok, I must have stated poorly- your explanation is better.