|
Hi all,
I am new to this forum and generally any programming help forum for that matter.
I have a case where i want to maintain both C and C++ api library. So therefore i choose to make my C++ support a thin wrapper around the C code. However, i do not know what is the most effective way to achieve this without unnecessary memory and performance overhead. Below is an example case.
/*Begin Code Sample*/
/*Start time.h*/
struct Time
{
int seconds,
int nanoseconds
};
void timeAdd(struct Time* time, struct Time* delta);
void timeSub(struct Time* time, struct Time* delta);
/*End time.h*/
/*Start timer.h*/
struct Timer
{
struct Time time;
void (*callback)(struct Timer *timer);
};
void timerSetCallback(struct Timer *timer, void (*callback)(struct Timer *timer));
void timerStart(struct Timer *timer);
void timerStop(struct Timer *timer);
/*End timer.h*/
/*Start time.hxx*/
namespace C
{
#include "time.h"
}
class Time
{
public:
Time()
{
m_time.seconds = 0;
m_time.nanoseconds = 0;
};
~Time(){};
int seconds(){return m_time.seconds;}
int nanoseconds(){return m_time.nanoseconds;}
void setSeconds(int seconds){m_time.seconds = seconds};
void setNanoseconds(int nanoseconds){m_time.nanoseconds = nanoseconds};
void add(Time &time){C::timeAdd(&m_time, &time.m_time);};
void sub(Time &time){C::timeSub(&m_time, &time.m_time);};
protected:
C::Time m_time;
};
/*End time.hxx*/
/*Start timer.hxx*/
#include "timer.h"
class Timer : public Time
{
public:
Timer():Time(){m_timer.callback = &Timer::callback;};
~Timer(){C::timerStop(&m_timer);};
start(){m_timer.time = m_time; C::timerStart(&m_timer);};
stop(){C::timerStop(&m_timer);};
protected:
static void callback(struct Timer *timer);
C::Timer m_timer;
};
/*End Code Sample*/
Now while this works for this simple case, it has a few drawbacks like the additional memory used to allocate m_time in class Time when all of struct Time api's would have even worked for struct Timer and hence struct Time m_time could have been "replaced" by struct Timer m_time but instead both exist in class Timer.
It also is the simpler of the cases where the struct sizes are relatively small and the call to Timer::start() was easily managed by a copy of the struct.
So now, my question is how can c++ wrappers be written for such cases without the additional memory overhead? Given their similarity, I definitely want class Timer to be a subclass of class Time!
However, i do have the flexibility to modify both the C and C++ code but i need both the C and C++ code to be equally capable, clean and efficient. How can i do it?
|
|
|
|
|
Kishore Jonnalagadda wrote: However, i do have the flexibility to modify both the C and C++ code but i need both the C and C++ code to be equally capable, clean and efficient. How can i do it?
Posting in the correct forum would be a good start.
Try here[^]
Prepare to be flamed.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
You should have started by reading the header of this forum, specifically where, in bold red letters, it says:
Do not post programming questions in this forum.
|
|
|
|
|
Probably the bold text should be in all capital and font size 36!
|
|
|
|
|
No programming questions in this particular forum
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
My apologies for being on the wrong forum. I have posted again at http://www.codeproject.com/script/Forums/View.aspx?fid=1647
Cheers!
Kishore
|
|
|
|
|
I encountered a project a few years back written by some indian guys in vb (they "apparently" had some c# background). everything was written as a function, no "subs" anywhere whatsoever.. All these functions returned nothing.. Their idea of code reuse was to bung everything into one huge global class and define it in every single page they wrote, even if no functions were used from that class (this was their idea of code reuse) . It was a joke.
On thinking back, this entire project qualifies as a coding horror so I couldnt paste any sample code..
|
|
|
|
|
Is it just me, or does anyone else find the fact that every coding horror written by an Indian gets mentioned, while all the coding horrors written else quietly go by without comment on the national origin of the perpetrator?
Not that I'd hint there's an undercurrent of racism in the programming community.
|
|
|
|
|
Rob Grainger wrote: Is it just me
Nope. Me too. I fully agree with you.
[added]
Private message for my silent troll: don't mind, I didn't forget your daily dish.
[/added]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Saturday, July 5, 2008 4:19 PM
|
|
|
|
|
Indeed, in cases like this, the mention of a nation or culture is isn't warranted; it adds nothing to the situation presented.
"Omit needless words" -- Strunk
|
|
|
|
|
Ahh the other part of the community that annoys me, the liberal "Politically correct" brigade.
If anyone bothers to read the post properly, I was describing the background of the said coding horror. Trust me if a contractor from the country I reside in did the same thing, I would throw their code straight back at them as well.. Chances are it would also appear on here as a coding horror..
The fact that annoys me is some contractors (and yes I am being general here!) feel they can get away with generating junk code written on the back of a fag packet, without any proper planning or ability, sellotape over the gaps and pass it off to niave managers as a decent perfectly working system (which then gets accepted by the company) just seriously annoys me.
I, and Im sure plenty of other people on this site, take great pride in constructing good quality code that makes efficent use of a programming language features, It seriously annoys me when so-called "programmers" and "analysts" produce junk and effectively con the end user or company purchasing the product. I have seen it happen so many times now in my 15yrs coding experience in many projects, and now its starting to depress me.. I am starting to ask questions as to why I bother anymore, why am I doing this job? Why do I bother coding to my exact standards and quality? , if managers look at the "pretty picture" rather than the quality of the underlying job.
Believe me, Programming, as it stands now is NOT a job I would reccomend my kids get in to. The Industry is being killed by too many "so-called" programmers, FROM ALL COUNTRIES.
Anyway, back to the topic... Isnt discussing coding horrors the whole point of this forum,or is the Politically correct brigade taking over here too?
|
|
|
|
|
GriffinPeter wrote: if a contractor from the country I reside
Exactly, therefore the race/culture of the idiot isn't relevent, nor is whether or not he was a contractor, so leave them out.
You quite correctly left out age, gender, sexual orientation, and hair color.
GriffinPeter wrote: discussing coding horrors
Absolutely, but leave out the irrelevent details. If for no other reason than to avoid dealing with yet other idiots trying to play the racist card. Don't give them opportunity to crawl from the woodwork.
|
|
|
|
|
PIEBALDconsult wrote: Exactly, therefore the race/culture of the idiot isn't relevent
You sure about that? Given that a lot of cheap outsourcing is done in India and outsourcing often has disastrous results, I think that perhaps you’re overreacting. Trying to save money is the cheapest way to lose money.
Steve
|
|
|
|
|
|
If you had said a French or Italian or English programmer I don't think you would have had the same response.
Some people confuse Indian with race whereas Indian is nationality and very probably culture and in my experience culture has a very definite effect on the quality and method of work.
After all I love German cars as they are engineered fantastically and Japanese bikes as they kick ass - does that then make me racist because of this?
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
From Wikipedia..
According to the United Nations Convention on the Elimination of All Forms of Racial Discrimination,
the term "racial discrimination" shall mean any distinction, exclusion, restriction or preference based on race, colour, descent, or national or ethnic origin which has the purpose or effect of nullifying or impairing the recognition, enjoyment or exercise, on an equal footing, of human rights and fundamental freedoms in the political, economic, social, cultural or any other field of public life
So, if the UN includes nationality as the basis of racism, that's good enough for me.
I'm sure if the OP had said "French, Italian or English" programmer, it wouldn't have had the same response. However, I never see that. The only time I see such references it almost inevitably refers to it as being Indian.
I agree the fundamental problem is out-sourcing resources, in that case refer to that as the actual problem, rather than unneccessarily drawing attention to the place that particular project was outsourced. I've seen, and unfortunately had to work on, some appalling outsourced projects within the UK as well.
|
|
|
|
|
Thanks for that definition Rob as I never realised that nationality plays a part in the definition of "racism" -I always thought it was with regards to race.
Guy
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
If I say I don't like VB as a language am I being Racist?
Come on guys stop being over sensitive.
I am an European Immigrant African living in Cape Town, South Africa what would you call me?
|
|
|
|
|
I think you have a good point, while at the same time from a professional point of view it is important to know what the definition of racism is as I need to know when what I say or do may land me in trouble even if it is an innocent remark.
Personally the racism of apartheid, and segregation in the US as well as the caste system in India are what I consider to be the most obvious and wrong forms of racism - when it comes to nationality it can start to become harder.
The next time someone offers me a cup of tea I will sue them for every penny they have for making a racist remark
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
I agree, but while the most obvious and wrong forms of racism, I still feel that treating a race/nationality or religious group (or gender) differently purely on that basis is unjustified.
Two strong examples spring to mind, still current.
(i) The pay gap - in most Western countries, there is still a disparity between the wages of male and female and workers from ethnic minorities - often simply manifesting as a "glass ceiling", fewer people from these groups get the top jobs.
(ii) The punishment gap. A white offender and a black offender committing the same crime tend to get different punishments. The death penalty in the U.S. is the worst, most drastic, example of this.
All I was originally trying to say is shouldn't we just not mention the nationality of these horrors - the horror itself should be enough.
|
|
|
|
|
Do you people know what racism is?
If in general code isnt as good by a certian group of people isnt that a correct statement?
|
|
|
|
|
RobParker wrote: Do you people know what racism is?
Nope, silly Briton.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'd like to see some empirical evidence that programmer's from India are worse programmers before a comment like that.
Actually, that subcontracted programmers in India are worse than subcontracted programmers generally.
(That was meant as a comment to Rob Parker's post)
modified on Monday, July 14, 2008 5:54 AM
|
|
|
|
|
How.. how... how were you able to access the source code of one of our client's electronic portal...??
Seriously, our client wanted us to maintain a demo web pages for that portal. They have been maintaining and adding the demo pages by stripping the asp code into static html. They sent me the demo pages for evaluation and when I see the zip file was like 50mb I was going "how the heck can html pages become so big"? Eventually, I found out that majority of the size is occupied by functions that are not used, and repeated in each pages.
Oh yeah, the portal was sub-contracted to India...
|
|
|
|
|
I am starting to feel, Programming as a Profession and Art Form died the day "Visual Programming" arrived (Delphi, Visual Basic etc...)
|
|
|
|
|