|
I'm writing code for a microcontroller in standard C and I'm compiling with GCC. My product has registers with addresses:
enum regAddr_e {
REG_A = 0,
REG_B = 2,
REG_C = 4
};
typedef struct {
regAddr_e regAddr;
uint16_t regValue;
} regAddrAndValue_s; When I want to write to registers, I create an array of regAddrAndValue_s and pass it to my write function. However, I have found that I quite often write to consecutive addresses so a lot of times only the start address would be needed:
typedef struct {
regAddr_e startRegAddr;
uint16_t regValues[];
} consecutiveRegAddrAndValues_s; However, as a documentation I would like to keep all registers visible in the code. So, I would like have a macro that does something like this:
#define MY_CLEVER_MACRO(__NAME_OF_STRUCT_VARIABLE__) \
REG_A, 0x0123, \
REG_B, 0x04567, \
REG_C, 0x89AB The macro should produce:
consecutiveRegAddrAndValues_s __NAME_OF_STRUCT_VARIABLE__ = {REG_A, {0x0123, 0x4567, 0x89AB}}; Also, if someone changes the register addresses so that a range is no longer consecutive, then I would like to throw a compile-time static_assert. Can someone please help me what MY_CLEVER_MACRO should look like?
|
|
|
|
|
If you want to 'document' where you're writing to, why not just provide several functions that offer this information right in their name? E. g.;
void setreg_A(uint16_t aval);
void setreg_B(uint16_t bval);
void setreg_C(uint16_t cval);
void setreg_all(uint16_t aval, uint16_t bval, uint16_t cval);
If that isn't what you want, what is? Can you show a line of code that would invoke your 'clever macro'? It's hard to say what is your intention without seeing how you're going to use it.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Just experienced an interesting behavior of my code AFTER getting cute and using "socket" for name of the return from
hci_open_dev .
The particular return was really described as "socket" - connection between processor and bluetooth "adapter" - but was originally named "sock".
After much search I realized that "hci" API names the return
"device descriptor"
and other known "opening device" function calls it "file descriptor".
Then I discovered "file handle " !
Is "handle" an ancient "windows OS" term ?
After this unpleasant experience I'll definitely NOT name anything "socket" , but I am curious what name would be really descriptive ( no pun intended ) for the return of generic "open_x" function ?
dev_descriptor = hci_open_dev(dev_id);
And if you feel it is a matter of personal preference, you do not need to state that.
Maybe it is covered in today's "ANSI C standards" - if there is such a thing.
Cheers
|
|
|
|
|
It is definitely personal preference.
|
|
|
|
|
What windows calls a handle, linux calls a descriptor.
They are very broad concepts which can basically be called a unique reference to something and/or anything.
Internally they are usually opaque pointers to some structure that is hidden from the caller for the exact
reason you just found out. They have no real meaning outside the API other than something to identify
something inside the API.
Generally I would call it a HANDLE on windows or a descriptor on linux. It really isn't a problem you should
be able to recognize one of your own HANDLES/Descriptors because you have to allocate it from somewhere and
then just typecast it to what it is.
RULE 1: Don't expose anything on an API you don't need too.
In vino veritas
modified 20-May-19 9:18am.
|
|
|
|
|
Vaclav_ wrote: Then I discovered "file handle " !
Is "handle" an ancient "windows OS" term ?
Pretty sure that it existed before windows.
I believe I was using "file handles" in Fortran/Pascal just about the time Bill Gates was still figuring out that college just wasn't for him. But perhaps that is a generic term rather than a specific one.
modified 23-May-19 12:09pm.
|
|
|
|
|
File handles certainly existed in MS-DOS (2.0 and later, released March 1983), and the term probably wasn't new even then.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Daniel Pfeffer wrote: File handles certainly existed in ... 1983 and were a good decade old by then. Unix dates from the early 1970s, and the concept and terminology of file handle was well established.
(With apologies to JSOP, "I'm old. I know things." )
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
OK. I thought that Unix called them descriptors.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Daniel Pfeffer wrote: I thought that Unix called them descriptors
I think that is the formal way it is used. But I found the other usage elsewhere.
|
|
|
|
|
jschell wrote: "file handles" in Fortran/Pascal Maybe in Pascal. (Early) Fortran used Unit numbers
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I wrote a very small program in VCPP long ago.
I have a Debug Folder and a Release Folder.
I cannot run the Debugger to access original source code.
I have Windows 7 Pro on 32-Bit HP 515n Pavilion, and it is not compatible.
Best advice heard- Put XP in VM and run it there.
I really do not want to do that if there is another way.
|
|
|
|
|
I've had a few programs which won't run on any Windows version later than XP (one of them being a game named Stars! which I kind of miss).
If you cannot or do not want to use a VM, I guess your best bet is to develop it on a supported Visual C++ release. If it is small, it may take less time and effort than to try to run an unsupported version of a now quite-old IDE.
noop()
|
|
|
|
|
I can run my small program called Notebook, and I can set compatibility for notebook.exe, but not notebook.dsw. It is presently a dialog box that asks a Question, and then provides the Answer.
I cannot use the debug folder to run debug.
I cannot rebuild.
I cannot compile.
I think it is just not compatible with Windows 7 Professional.
I am considering putting Windows XP SP3 in a VM, and running it there.
Mainly, I just wanted to see my original written form of Visual C++ 6.0 coding.
Then I can add Rich Text Format to the text entered.
Later on, I want to add vector graphic calculations to the result.
|
|
|
|
|
Michael Hinton wrote: but not notebook.dsw .dsw files are generally opened by either Borland C++ compiler or Visual Studio. It does not seem to be an executable file (like an .exe file is); thus, there is no "compatibility mode" for dsw files.
Michael Hinton wrote: Then I can add Rich Text Format to the text entered.
Later on, I want to add vector graphic calculations to the result. Since you may add further functionalities to your project, redevelopping it under a more recent platform may allow you to find more resources, or at least to find them more easily.
Good luck anyway on your new development trip
noop()
|
|
|
|
|
Go to the Debug or Release folder (as appropriate) in Windows Explorer. Right click the mouse on the executable program, and select "Properties". You can then set it to run in compatibility mode; no guarantees but it often works.
|
|
|
|
|
I can run my small program called Notebook, and I can set compatibility for notebook.exe, but not notebook.dsw. It is presently a dialog box that asks a Question, and then provides the Answer.
I cannot use the debug folder to run debug.
I cannot rebuild.
I cannot compile.
I think it is just not compatible with Windows 7 Professional.
I am considering putting Windows XP SP3 in a VM, and running it there.
Mainly, I just wanted to see my original written form of Visual C++ 6.0 coding.
Then I can add Rich Text Format to the text entered.
Later on, I want to add vector graphic calculations to the result.
|
|
|
|
|
Michael Hinton wrote: can set compatibility for notebook.exe, but not notebook.dsw Well a .dsw file is not an executable so why would you want to set compatibility mode for it? And having set compatibility mode for notebook.exe, what happens when you run it?
|
|
|
|
|
This is not a Joke!
A few weeks ago, the NSA released a disassembly tool, ghidra, into the public domain. It is in theory only downloadable from the USA, but no one outside the USA has ever heard of VPNs. /s
I've used it on some object code, and managed to reconstruct a C version at a level that allowed me to understand what the object code was doing. It's not good enough to recompile, but you should be able to see how the code works.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I can run my small program called Notebook, and I can set compatibility for notebook.exe, but not notebook.dsw. It is presently a dialog box that asks a Question, and then provides the Answer.
I cannot use the debug folder to run debug.
I cannot rebuild.
I cannot compile.
I think it is just not compatible with Windows 7 Professional.
I am considering putting Windows XP SP3 in a VM, and running it there.
Mainly, I just wanted to see my original written form of Visual C++ 6.0 coding.
Then I can add Rich Text Format to the text entered.
Later on, I want to add vector graphic calculations to the result.
|
|
|
|
|
So you can open your project with VC6, but you can't debug it? Or can you not open the project at all?
I still use VC6 on a Windows 7 machine for one of my main projects still today and it works just fine. When I initially put it on that machine 5+ years ago, I had to tweak some files to get it going (because it was 64-bit), but it has run fine ever since.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I can run my small program called Notebook, and I can set compatibility for notebook.exe, but not notebook.dsw. It is presently a dialog box that asks a Question, and then provides the Answer.
I cannot use the debug folder to run debug.
I cannot rebuild.
I cannot compile.
I think it is just not compatible with Windows 7 Professional.
I am considering putting Windows XP SP3 in a VM, and running it there.
Mainly, I just wanted to see my original written form of Visual C++ 6.0 coding.
Then I can add Rich Text Format to the text entered.
Later on, I want to add vector graphic calculations to the result.
|
|
|
|
|
Michael Hinton wrote:
I cannot use the debug folder to run debug. What exactly does this mean?
Michael Hinton wrote:
I think it is just not compatible with Windows 7 Professional. Your app or VC6?
Michael Hinton wrote:
Mainly, I just wanted to see my original written form of Visual C++ 6.0 coding. So are the H/CPP files not present?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Do you have all the needed source files? Or you only nave a .dsw one?
Do you have some VS installed on your PC? Which one?
|
|
|
|
|
Hi Victor,
I am not sure I am using the CodeProject System correctly!
Am I expected to give an up or down vote with the red and green triangles?
I am using Visual Studio 6.0. The dsw file just brings up the program in workbook form.
I can only go into Properties from Notebook.exe for XP Compatibility plus Run as Admin, and that is not helping me to get the coding I want to look at. I want to add RTF to my text, and later graphics in the Answer section.
The Notebook program was written in Visual C++ but mostly C++.
It is a simple Q & A dialog box I programmed for study questions and answers.
I wrote that program in Feb. 2004, and I am now retired, so I want to get back to learning.
I have a considerable investment in the VCPP6 and VB6 library volumes.
I want to stay with VS6 because the programs will be only for me, and I do not intend to write many.
I can see the compiled code, but I cannot regenerate my original write-up code from that!
If I run the debug there is supposed to be a way to make a file that tracks my code, but that is during the original compile and debug process. Only Windows XP is compatible with my program.
I have Windows 7 Pro now on my HP Pavilion 515n 32-bit computer and running compile, rebuild, or debug just destroys the program. Fortunately I keep backups of Notebook. It runs fine on Win7, but not much use to understand my original write-up code way back then!
I mainly use the 32-bit to backup my Palm Pilot monthly and run a free-space drive wipe after.
Don't worry, I have an HP ENVY 700-210xt SSD 64-bit on Windows 10, but free-space wipe on it would be write steps that burn SSD life (read is fine, but not write). Also, I want to keep my programming mess away from the 64-bit computer.
I am currently looking into using a VM with Windows XP inside to run my program with all functions.
|
|
|
|