If you have common functionality in two products, what's wrong with abstracting the common functionality into a shared module (or library)? You then have only one definition to worry about, and don't need this macro at all. The bonus is that the code need be maintained once only.
If the products have different functionality but happen to share the same register numbers, they are two different products.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
It's not common functionality, they are products that can be connected/disconnected on the fly and they have a bus in between them (when connected). The register set I want to expose to the other product is a subset of all the registers, that are only available to an administrator PC-application via a USB-cable.
In the shared h-file I also have some structs and enums that are needed to understand what the bytes in the different registers mean.
It doesn't change what he said generally you want to abstract the interface to functionality not physicality ... you are connecting things.
You are doing "things" when you have to access the registers, you don't just randomly decide to access the registers.
At the moment you are worrying so much about the physical you aren't even thinking about the functionality.
If you consider something like ReadFile or WriteFile they are functions, yet they can whack all sorts of registers from COM port, USB drives, SATA drives. You don't have to provide registers to those functions it works it out from the name and it is all nicely hidden behind the interface. Even consider ethernet socket programming, lots of registers getting used but not once do you ever deal with them. You deal with functionality connect, listen, send, poll etc.
If you consider Linux and Windows and how complex they are they never expose registers outside the driver and the driver interface is purely a functional api. Granted they have the added problem they may need to share registers between threads/tasks etc but that is just another reason to hide register access below a functional abstraction.
So stop and think what functionality are you doing when you need to whack the registers and can you make a nice functional interface that hides the registers into a common block so they don't ever have to be exposed.
My product is quite low-level, i.e. I'm setting up impedances, gains, current limiters, bias voltages, differential signal on/off, generating PWM signals, etc. Also, communication protocols are cascaded, for example a PC is transmitting a USB-packet to a microcontroller, who in turn forwards this over an SPI-bus to another microcontroller, who in turn forwards this over a CAN-bus, etc and then an ACK/NACK-packet has to travel the opposite direction. So, to have "local" interfaces between different microcontrollers would make this packet forwarding extremely confusing. Especially the CAN-bus is a bit troublesome because of the limited payload size (8 bytes/packet and no, we can't use the improved version that clocks the data faster) and sometimes I need to send several kBytes of data.
I have a table in Excel (i.e. tab-separated data) that I want to copy-and-paste into a C-file. I would like the table to be readable in the C-file as well, i.e. it should be nicely formatted into aligned columns. If I do a "dumb" replace-tabs-with-spaces then my column alignment gets messed up due to the text in the cells not being equal width. Does anybody know of a tool that can convert my tabs with a variable number of space and preserve the nice column alignment?
It is no good replacing tabs with some number of spaces. Tabs are markers which indicate that the next item should be placed on a tab boundary. Boundaries are on the next column which is a multiple of the tab width (usually 4 or 8). So a tab may represent any number of spaces from 1 up to the tab width.
Are you pasting this as comments in your C file or as data to be displayed? If the latter then the tab characters should work.
Since the process involves the use of the clipboard, there are a couple of solutions which come to my mind:
You could create a VBA macro in Excel which would format the contents:
You would need some PADLEFT or PADRIGHT kind of function:
Function PadLeft(text As Variant, totalLength As Integer, padCharacter As String) As String
PadLeft = String(totalLength - Len(CStr(text)), padCharacter) & CStr(text)
Function PadRight(text As Variant, totalLength As Integer, padCharacter As String) As String
PadRight = CStr(text) & String(totalLength - Len(CStr(text)), padCharacter)
Then use one of these functions to pad the values to the width of the largest value and place the result in the clipboard.
Have a button in Excel which launches the macro (whose result will be formatted text exported to the clipboard).
Or find an utility which can automatically format the content of the clipboard according to a specified format string. Honestly, I have never searched for such a tool, I don't even know if that exists.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
It is impossible only excel knows how wide the original columns were, that is why it puts the delimiters in the text to mark the columns
So if you want the original column width in excel you need to get excel to put them in a cell so it gets exported with the data and you can then use it to reformat the layout.
I know for say cell A1 width the excel formula is =CELL("width", A1) which displays as a decimal number.
What exactly that number is I have no idea but you can try searching for it or just play with a few letters and font heights and you should be able to work it out.
I know but you aren't really looking at problem. The fonts in the cells are true type proportional not old school fixed pixel fonts so unless you have display formats on them you are dead out luck they wont be fixed character widths.
So the best you can probably do is the pixel width and then divid it by some number so if the font sort of averages 10 pixels width the 100 pixel column = 100/10 = 10 characters and 150 pixel width column gives you 15 characters.
You aren't going to be able to do much better than that at at least it will be somewhat columnized