For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
I am programming regular C for an embedded ARM processor. I need to declare an array with volatile elements inside it. The location of the array is constant, it's only the elements inside the array that can change and they are, like I said, volatile. What is the correct way to declare it?
A. uint8_t volatile UARTrxBuffer;
B. volatile uint8_t UARTrxBuffer;
C: volatile uint8_t volatile UARTrxBuffer;
The general answer is B but in your case there is no difference between A and B, and C would generate a compiler error.
It can be better explained when having a dynamically created array:
// my_data1 is a volatile pointer
uint8_t* volatile my_data1 = (uint8_t* volatile)malloc(10);
// The array elements are volatile
volatile uint8_t* my_data2 = (uint8_t*)malloc(10);
// Both are volatile
volatile uint8_t* volatile my_data3 = (uint8_t* volatile)malloc(10);
With the volatile pointers, the casts must also contain the volatile keyword.
But with arrays, the pointer can't be re-assigned so that version C is not allwed and the position of the volatile keyword does not care.
I am confused what Jochen is saying to you but I will say nothing you nor Jochen have code will make the items within the array volatile.
First lets cover the basics volatile is an optimizer instruction it has very little to do with the C language as such it is also HIGHLY vendor sensitive. So the first thing you always need to do is check your vendor tools and specification.
My next warning is to always put the volatile between the type and the name not at the front as people love to do. Things like the arm compilers are notorious with volatile in the front of the type and if you use it in macros you will end up with it on the wrong thing. I covered this in a recent article on baremetal with the RPi but Arm covers this in there documentation ARM Information Center[^] You see the format, that is not just the arm standard it is the standard I suggest you use as most embedded compilers get it right
type volatile * const ptr;
| | | | |
| | | | +------> ptr is a
| | | +-----------> constant
| | +---------------> pointer to a
| +---------------------> volatile
Almost all vendor tools will fail to do with volatile what the full C specification says because the specification isn't written by embedded processor vendors and they get little say in it. Some of the junk that is in the C specification around the word volatile is ignored because it doesn't make sense in micro-controllers. The scary stat is 96% of vendor tools fail the full C implementation (Testing result reference :[^])
So lets get down to specifics the volatile must also be on any item within the array putting a volatile on the array itself will not work almost any compiler. The compiler doesn't see "blocks" of things as volatile it only sees things it is accessing in the mode it is accessing them as volatile.
The fact you want a volatile inside a malloc would tend to indicate you are playing around with a DMA controller so I will reference hardware access here. If this is just shared multitask memory nothing changes it's just simpler to understand.
This is a basic hardware register definition example for something like a DMA controller
typedef uint32_t volatile rwreg32; // 32 bit read/write register
typedef uint32_t constvolatile readreg32; // 32 bit read only register
I can then define an array of them and the volatile will be on each and every array item because when the C compiler picks up an array entry they are a type which includes the word volatile. Note if you accessed the enteries as words or bytes those accesses would not be volatile, it is that specific.
You notice there is no word volatile on the array itself that is pointless and won't work unless you were passing the whole array to something. The same situation exists with structs if you wish to use them as representations of hardware. The volatile must be on each item in the struct AS IT WOULD BE ACCESSED and even down to bit packs if that is how you access them. Here is a small random sample from an OTG chipset struct
You see how they have put volatile on each entry in the struct as they would be accessed, and as the struct itself may be accessed as a whole it is put on the struct itself.
So basically however you access the hardware must be seen as a volatile type, just putting volatile on something doesn't make it volatile as a whole if you don't access it that way. So even declaring something like a register as volatile doesn't work if you access the register as bits. Many micro-controllers have bit operations they can do on registers and special hardware and that is what those who write the C specification seem to not understand time and time again. Some vendors will allow you just to mark the register as volatile but many more require you to mark each bit within the register as volatile if you use bit operations. That is why many vendors tools have a more simple definition called SFR for special function register where they do the volatile on everything for you.
So this is why the correct way to do this is however your C tool vendor says to do it because the C standard may be of little help on anything more than a simple shared memory use of the word. In 4 revisions of the C standard the committee hasn't even managed to give us a way to define a write only register which almost every micro-controller has, so don't expect them to deal with volatile anytime soon.
If you are on something like an ARM6+ it gets worse the C standard has no idea what to do with Out-Of-Order-Execution processors like the Arm Most of the new fancy phones run Weakly-Ordered CPU's and if you are coding for them you need to understand how to deal with it and a few more tricks you won't find in the C standard. I bring it up because on those you don't even write directly to the hardware (there is a cache between you an it) so the idea of volatile gets even more convoluted.
created a Dialog base Application with Tree control..Now i had Selected some leaf item from my tree control ,And after that click on to open any dialog then the Tree Leaf unselected. Now i want tree item should be selected after closing the dialog.
Now I tell u full story. when i drag the item into grid it also add into TreeView.Now suppose there are 3/4 item into editor and u select one the parallely tree item will also select.so now this time both the thing are selected but as u will click some where else like open an dialogbox and close it then tree item will be selected but partially it`s colour will be Gray..now my problem is that Gary colour. I need it Fully selected Item.
That should be the way is works. Each thread should acquire the Mutex (i.e. lock it) in order to protect the data. When they finish the critical section they should Release it. The point being that you only want one thread through this path at any one time.
i need help for this project. I would glad if someone could help me with my concern. Create in C/C++ client and server application for UNIX operating system using BSD sockets (located at eva.fit.vutbr.cz or merlin.fit.vutbr.cz) which will provide directory service (small LDAP) . • Final programs should be compiled into filename called client and server. • Create makefile which can be used for automatic compilation of source files by typing make statement in UNIX shell. • All errors should be printed on stderr. • Directory database will be presented as text file (CSV format) with following syntax: • “id,login,surname,firstname,faculty” . Each entry (line) is terminated by \n character.
We do not do your HomeWork. HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them. Any failure of you will help your teacher spot your weaknesses and set remedial actions. So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
In any case, game development in C++ will be tough, and if you are a beginners don't even bother.
If you are a beginner then Java or C++ doesn't make sense or difference. You can develop performance-ready games in Java too. For that, I would recommend having a good understanding of many things, there are books available; tutorial or article won't be enough.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
Last Visit: 31-Dec-99 19:00 Last Update: 10-Dec-16 14:39