473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Understanding structures and pointers..?

Hi
I am a newby to C trying to get my head around some basic structure syntax within an embedded ARM FM4 environment.
I am trying to understand the meaning of the * character in the following statement..?


Expand|Select|Wrap|Line Numbers
  1. #define FM4_GPIO ((FM4_GPIO_TypeDef *)FM4_GPIO_BASE)
Can anyone help please..?
Aug 13 '14 #1

✓ answered by donbock

Generally in C, pointers are assigned to the address of some variable. For instance:
Expand|Select|Wrap|Line Numbers
  1. int a;
  2. int *pa = &a;
Something different is needed if you want to point at a memory-mapped I/O location. Suppose the hardware/software interface manual for your system tells you that a memory-mapped I/O device is at address 0xDD800000 and that the device must be accessed with 32-bit bus transaction. A common idiom in C is:
Expand|Select|Wrap|Line Numbers
  1. #define DEVICE_ADDR 0xDD800000
  2. int32_t * const pDevice = ((int32_t*)DEVICE_ADDR);
The #define associates a macro name with the address of the device. Thus, there is only one place in your code (the #define itself) where the specific hex address of the device appears. Everywhere else reference that value with the descriptive macro name.

The next line defines a pointer to 32-bit memory and sets the pointer to the address of the device. The cast is needed to tell the compiler (and more importantly, the next person to read the code) that you meant to assign an integer value to a pointer. You can use this pointer to read from or write to the device.

The const is positioned so that the value of the pointer cannot be changed - it always points to the device.

I'm only guessing this is what your code is doing; but it seems likely. GPIO might stand for "general purpose I/O".

3 1259
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. #define FM4_GPIO ((FM4_GPIO_TypeDef *)FM4_GPIO_BASE)
The is a pre-processor directive (the line starts with a #). The pre-processor scans the code and does a global search and replace. In this case anytime FM4_GP10 is located, it is changed to (FM4_GPIO_TypeDef *)FM4_GPIO_BASE.

What this does is change all FM4_GP10 into a type cast of FM4_GP10_BASE to a pointer to FM4_GP10_Typedef.

The exact meaning can only be determined from the code. In any case, this is not good stuff for a newbie to C. This is kind of like learning a foreign language and you have encountered a rarely used big word. I suggest you accept this on face value and move on to understand such parts of the code as you can.

If the original author is still around you can get a complete explanation there.
Aug 13 '14 #2
donbock
2,426 Expert 2GB
Generally in C, pointers are assigned to the address of some variable. For instance:
Expand|Select|Wrap|Line Numbers
  1. int a;
  2. int *pa = &a;
Something different is needed if you want to point at a memory-mapped I/O location. Suppose the hardware/software interface manual for your system tells you that a memory-mapped I/O device is at address 0xDD800000 and that the device must be accessed with 32-bit bus transaction. A common idiom in C is:
Expand|Select|Wrap|Line Numbers
  1. #define DEVICE_ADDR 0xDD800000
  2. int32_t * const pDevice = ((int32_t*)DEVICE_ADDR);
The #define associates a macro name with the address of the device. Thus, there is only one place in your code (the #define itself) where the specific hex address of the device appears. Everywhere else reference that value with the descriptive macro name.

The next line defines a pointer to 32-bit memory and sets the pointer to the address of the device. The cast is needed to tell the compiler (and more importantly, the next person to read the code) that you meant to assign an integer value to a pointer. You can use this pointer to read from or write to the device.

The const is positioned so that the value of the pointer cannot be changed - it always points to the device.

I'm only guessing this is what your code is doing; but it seems likely. GPIO might stand for "general purpose I/O".
Aug 13 '14 #3
Hi Everyone - Thank you for your help with this I guess I will go back to writing in assembler for now until I can get my head around some of these convoluted C structures..!
Sep 3 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Joolz | last post by:
Could someone please give me an example of how to make pointers to nested structures? Pointers to normal structures are no problem... struct structA { int a; }structA_s; structA *pStructA =...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
79
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The...
1
by: ketema | last post by:
Hello, I was wondering if someone could help me with a function I am trying to write. The purpose of the function is to read in text from a file in the following format: FIRSTNAME LASTNAME...
11
by: Satish Kumar | last post by:
Can any one give me indetail about, what are pointers? How are pointers useful in C prgramming? How do they work? i had gone through one book, i am a bit confused. Regards, Satish...
39
by: anonymous | last post by:
Dear All, >From my understanding of pointers, a pointer should not be able to access a memory location until that memory has been allocated either by assiging the address of a variable or...
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
3
by: sajohn | last post by:
I'm fairly new to c programming and am not very clear on pointers and handles. Currently, I'm writting a wrapper script and I need to interface with another application. I have decided that the...
5
Nepomuk
by: Nepomuk | last post by:
Hi! I'm learning C++ and have just read about Pointers and References a bit. Now I'm not absolutely sure, that I've understood it correctly. I asume, that (taking an example from the real world)...
2
by: maricusmayunga | last post by:
Hi guys, I am brand-new to pointers and c++. I want to do simple program to capture some 5 surnames of people(employees) - using array and pointers. Well I understand a bit of arrays and I know how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.