473,498 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using different constants for different porjects.

Hello,
I've written a program for a usb controller. I want to change some data
strings for another project so that program code remains the same. Some data
is hardcoded like

BYTE code UsbRomStringsLangId[] = {
4, // Length of language descriptor ID
3, // LANGID tag
9, // Low byte of 0x0409 (English)
4 // High byte of 0x0409 (English)
};
BYTE code UsbRomAcmInterfaceString[USB_ACM_INTERFACE_STRING_LENGTH] = {
USB_ACM_INTERFACE_STRING_LENGTH, DESC_TYPE_STRING, //"CDC-ACM Comm"
'C', 0, 'D', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'C', 0,
'o', 0, 'm', 0, 'm', 0, 0, 0};
BYTE code UsbRomCdcInterfaceString[USB_CDC_INTERFACE_STRING_LENGTH] = {
USB_CDC_INTERFACE_STRING_LENGTH, DESC_TYPE_STRING,
'C', 0, 'D', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'D', 0,
'a', 0, 't', 0, 'a', 0, 0, 0};

How can I do that?
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 14 '05 #1
3 1180

"valentin tihomirov" <va*********************@abelectron.com> wrote in
message news:cl****************@plethora.net...
Hello,
I've written a program for a usb controller. I want to change some data
strings for another project so that program code remains the same. Some data is hardcoded like

BYTE code UsbRomStringsLangId[] = {
4, // Length of language descriptor ID
3, // LANGID tag
9, // Low byte of 0x0409 (English)
4 // High byte of 0x0409 (English)
};
BYTE code UsbRomAcmInterfaceString[USB_ACM_INTERFACE_STRING_LENGTH] = {
USB_ACM_INTERFACE_STRING_LENGTH, DESC_TYPE_STRING, //"CDC-ACM Comm"
'C', 0, 'D', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'C', 0,
'o', 0, 'm', 0, 'm', 0, 0, 0};
BYTE code UsbRomCdcInterfaceString[USB_CDC_INTERFACE_STRING_LENGTH] = {
USB_CDC_INTERFACE_STRING_LENGTH, DESC_TYPE_STRING,
'C', 0, 'D', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'D', 0,
'a', 0, 't', 0, 'a', 0, 0, 0};

How can I do that?


Remove the hardcoding, store your strings externally (e.g. in a file
or 'registry', etc.), and have the programs load them.

-Mike
Nov 14 '05 #2
"valentin tihomirov" <va*********************@abelectron.com> wrote in message news:<cl****************@plethora.net>...
Hello,
I've written a program for a usb controller. I want to change some data
strings for another project so that program code remains the same. Some data
is hardcoded like

BYTE code UsbRomStringsLangId[] = {
4, // Length of language descriptor ID
3, // LANGID tag
9, // Low byte of 0x0409 (English)
4 // High byte of 0x0409 (English)
};
BYTE code UsbRomAcmInterfaceString[USB_ACM_INTERFACE_STRING_LENGTH] = {
USB_ACM_INTERFACE_STRING_LENGTH, DESC_TYPE_STRING, //"CDC-ACM Comm"
'C', 0, 'D', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'C', 0,
'o', 0, 'm', 0, 'm', 0, 0, 0};
BYTE code UsbRomCdcInterfaceString[USB_CDC_INTERFACE_STRING_LENGTH] = {
USB_CDC_INTERFACE_STRING_LENGTH, DESC_TYPE_STRING,
'C', 0, 'D', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0, 'M', 0, ' ', 0, 'D', 0,
'a', 0, 't', 0, 'a', 0, 0, 0};

How can I do that?


Rather than defining these variables at compile time do so at runtime
during initialisation. Write a function to convert a string into the
form you need, so:

interleave_with_zero("CDC-ACM Comm")

returns 'C', 0, 'D', 0, 'C', 0, ...

You should do something like this anyway, for clarity.
Nov 14 '05 #3
valentin tihomirov wrote:

Hello,
I've written a program for a usb controller. I want to change some data
strings for another project so that program code remains the same. Some data
is hardcoded like

BYTE code UsbRomStringsLangId[] = {
4, // Length of language descriptor ID
3, // LANGID tag
9, // Low byte of 0x0409 (English)
4 // High byte of 0x0409 (English)
};

.....

A common way is to use conditional coding for the variant parts:

#if SYSTEM==SYSTEM_A
const char foo[] = {"init sys A"};
#elif SYSTEM==SYSTEM_B
const char foo[] = {"init sys B"};
#else
#error SYSTEM undefined
#endif

You can have your makefile or project file define SYSTEM for the
perspective build.

Another way is to isolate all the system-dependent items in a module
which ONLY holds the dependent items and only compile the version that
matches the target being generated.

Thad
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3671
by: Christian Hackl | last post by:
I honestly wasn't able to find an answer for this design question using Google and Google Groups, so I apologize if it is asked too frequently :) Anyway: Let's say I have a multidimensional array...
4
2132
by: JR | last post by:
Hey all, I am passing a two dimensional array to a function. It basically looks like this int test(double array2 , const CONST1, const CONST2) { int returnValue; for (int i = 0;...
13
6053
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
11
6548
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
5
1571
by: Valentin Tihomirov | last post by:
I have a .c file with a general code. It can be compiled with different constants for different applications. For example char a; where BYTE_SIZE is a constant defined in an external (.h?)...
1
2733
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
1
1356
by: wadefleming | last post by:
I have the following code which I am having trouble with. The problem is detailed in the comments near the end. Constants.cs: -------------- namespace MyApp.Const { public class Const {...
4
3665
by: Jarod_24 | last post by:
I've managed find out how to start using the Win32 API's But some of these methods got constants that you should use when caling them. for example the LockSetForegroundWindow got a unsigned...
8
4780
by: ewpatton | last post by:
I have a header that is shared among different CPP files for constants. When Microsoft Visual C++ links the .obj files, it complains that these names are all duplicates. How can I get it to realize...
3
1583
by: mattyizzo | last post by:
Here is my code. Basically I'm trying to solve for CI and CF, where each use a bunch of constants and a variable or two which can have up to 10 values. I get the following error, however, at line...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7208
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...
1
6890
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
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.