473,395 Members | 1,975 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,395 software developers and data experts.

Cheating C

I am trying to write a single function that can handle a string or number as one of its input parameters. In an ideal situation this might be

at_wr("CH","text string");
at_wr("NI",0x234);

This is to be used on a Hayes type modem AT command set. There are various commands CH,NI,ID,PL etc followed by a text string,or a 16bit or 32bit number. I was thinking that from the commands CH for instant, I know (and the compiler can know) that the argument following is a text string. Similarly NI is always followed by a number. I know I can do something like

at_wr_str("CH","text string");
at_wr_u16("NI",0x2345);
at_wr_u32(" etc....

ie. make different functions, but is there any other way of telling or tricking the compiler to accept my 1st example. I looked at unions, macros, thought about using pointers. C++ seems to have the answer with the ability to overload a function name so the complier matches the function definition to the arguments.

I am a bit stumped, but I thought I would just ask before resorting to writing the 3 or 4 different function names I need. One function would be more elegant..
Nov 11 '06 #1
6 1933
horace1
1,510 Expert 1GB
why not use overloaded functions in C++? i.e. two different functions can have the same name if their parameter types or number are different. see
http://www.cplusplus.com/doc/tutorial/functions2.html
Nov 11 '06 #2
Yes, but I'm using a Keil C compiler for an ARM microprocessor and I dont think C++ is an option, I wish it were. I am pretty new to C and am just hoping there is a way of doing what I would like to do.

Maybe I could treat everything as a text string and convert as required ie.

at_wr("CH","text string");
at_wr("NI","0x234");
Nov 11 '06 #3
horace1
1,510 Expert 1GB
Yes, but I'm using a Keil C compiler for an ARM microprocessor and I dont think C++ is an option, I wish it were. I am pretty new to C and am just hoping there is a way of doing what I would like to do.

Maybe I could treat everything as a text string and convert as required ie.

at_wr("CH","text string");
at_wr("NI","0x234");
I thought that the Keil development environment for the ARM supports C and C++ - try a simple program and see.
Nov 11 '06 #4
Your right, but no one seems to have tried it, I asked the question of the Keil Forum and .....nothing. I will try a "hello world".
Nov 11 '06 #5
Banfa
9,065 Expert Mod 8TB
Use a function with a variable parameter list (like printf)

void at_wr(char *cmd, ... );

use the macros va_start, va_arg, va_end and the type va_list defined in stdarg.h to access the data following command in the function call.

The only requirement is that whatever cmd points to must identify the type of the following parameters.
Nov 11 '06 #6
Thanks. I tried a simple C++ in Keil and it doesn't work so I posted a question in Keil forum to ask if anyone has tried it yet.

Banfa - you read my mind, I am trying to get a simple version working right now.
Nov 12 '06 #7

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

Similar topics

0
by: Auction Tutor | last post by:
Still wasting your time with Google searches that go nowhere? http://transversal.tealpage.com/download1/gen0/index.html
7
by: Milk | last post by:
Anyone can help me to do this program, i will pay for it coz i really don't have time to do it and i need hand it in 22/04. Pls help me and reply about how much u want i pay for this program??...
4
by: Chris | last post by:
I want to cheat on some certs to get ahead, is this a good idea? can microsoft catch me? chris
49
by: vfunc | last post by:
If I have a large array 10,000+ elements then how do I reserve memory for this ? Currently I get a segmentation fault. Dynamic reservation is good, but allowing a chunk for the program is an...
10
by: preethamkumark | last post by:
- The program first creates a shared memory buffer containing an array of 20 integers. - Each slot of the buffer can have either 0 or 1, where 0 represents an empty slot, and 1 represents an...
1
by: morpheus123 | last post by:
How to find out if your boyfriend is cheating If you want to know the truth - FREE Use this dream time technique It works in ONE DAY. This is how to use your dreams to find out if your...
5
by: Daikide | last post by:
I need to translate this formula into C code, but I know very little programming. Can anyone help? http://mathworld.wolfram.com/images/equations/MeanDeviation/equation1.gif
1
by: n87ujkb3 | last post by:
We hear that some women say that their men are cheating them from time to time. Sometimes they are right that their men are really cheating them. However, the fact is that they will be wrong most...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.