|
|
I ran into some linker warnings about multiply defined symbols in a very large application (20 VC projects). I tracked it down to someone defining a function within the header file. I personally think it's lazy coding but that's just my opinion and we all know what those are....
<br />
#pragma once<br />
class Foo<br />
{<br />
public:<br />
Foo();<br />
virtual ~Foo();<br />
<br />
int GetBar() const { return m_value; };<br />
<br />
private:<br />
int m_value;<br />
};<br />
The header file is used across multiple static library projects. Each static library exports the symbol Foo::GetBar. The application project then links in all the static libraries spitting the warnings LNK4006. Does anyone have a technical explanation why the #pragma once doesn't prohibit this type of error and/or why each static library exports Foo::GetBar? Thanks.
harrier
-- modified at 12:12 Thursday 12th January, 2006
|
|
|
|
|
#pragma once only causes the header to be included a single time per compilation unit. Each source file is a separate compilation unit. A static library is a collection of one or more compilation units.
Each static library contains Foo::GetBar because each one included the header file to get the definition of Foo.
If you did not think GetBar would ever be overloaded by a dervied class, I would just tag that sucker as inline and get it over with.
Marriage slows down your coding, a baby slows it down even more!
|
|
|
|
|
Blake Miller wrote: Marriage slows down your coding
maybe...
Blake Miller wrote: a baby slows it down even more!
...but it's so sweet that it shouldn't even be compared to...
when you don't give time to you compiler, it will stay as is.
if you don't give time to your baby, he will grow up with a missing father !
make your choice.
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
|
Blake Miller wrote: If you did not think GetBar would ever be overloaded by a dervied class, I would just tag that sucker as inline and get it over with.
thats interesting - I wouldnt have thought of that if it had been me - I would have ripped the function implementation out into its own cpp
the things you learn by sitting back and watching sometimes
cheers, Garth
|
|
|
|
|
implementing the function in the class itself are called inline functions.
-Prakash
|
|
|
|
|
thanks Mr P. I knew that (what inline was) - I didnt know that making it inline would get around that particular 'multiple define' issue
'g'
|
|
|
|
|
#pragma once just causes the compiler to process an include file only once per build... that has nothing to do with the linker.
Don't try it, just do it!
|
|
|
|
|
Hi
I get from an application a UTC time value in the following variables : nyear, nmonth, nday, nhour, nminute, nsecond.
I need to convert this UTC time value in a time_t format (also UTC), whatever the time zone and the DST of the computer.
I've tried with a CTime object, but CTime::GetTime() considers that it contains a local time, and take into account the time zone. (I can only remove the DST effect)
Thank you for any idea ?
Jérôme
|
|
|
|
|
I think if you first fill a SYSTEMTIME structure with the nyear, nmonth, nday... values then use it in your CTime constructor your times will work.
ie.
<br />
<br />
SYSTEMTIME st;<br />
st.wYear=nyear;<br />
st.wMonth=nmonth;<br />
st.wDay=nday;<br />
st.wHour=nhour;<br />
st.wMinute=nmin;<br />
st.wSecond=nsec;<br />
CTime mytime(&st);
<br />
Regardless if that particular method works or not. If you use SYSTEMTIME object there's a bunch of functions available to go back and forth between time zones that may make your life easier.
|
|
|
|
|
Thank you for your answer.
When creating "CTime mytime(&st);" with the SYSTEMTIME st value I assume that the CTime constructor takes into accout that the given time is UTC time, and it must apply the local time conversion ?
So when I execute time_t t_utc = mytime.GetTime(), I get a UTC time in t_utc ?
Is it the way it works ?
|
|
|
|
|
Well, like I said before, it's been a while since I've used time structures and objects, but I have used them extensively in the past.
If you Do just a little playing around and debugging the SYSTEMTIME variable (it's easiest because all the members are .hour, .min, .sec and you can watch the values directly) I'm fairly sure will reveal that it always works in UTC timezone. The companion functions Format() etc. all add in timezone offsets.
This means you're thinking a little backwards as to when the timezones come into play, but it depends on which actual Structure or object you are talking about.
Just do a little debugging, it will become clear very quickly.
Oh and do yourself a favor, leave yourself lots of comments so you remember later. I looked through my old source and I forgot that part which is why I can't answer your question directly
|
|
|
|
|
I've finaly found a solution :
time_t system_time, time_tloc, time_tgmt;
struct tm loctime, gmttime;
time(&system_time);
loctime = *localtime(&system_time);
gmttime = *gmtime(&system_time);
time_tloc = mktime(&loctime);
time_tgmt = mktime(&gmttime);
long offset = time_tloc - time_tgmt;
CTime t(nAnnee,nMois,nJour,nHeure,nMinute,nSeconde, -1);
time_t lRetValue = t.GetTime() + offset;
Thank you for your help.
Jérôme
|
|
|
|
|
try GetLocalTime and GetSystemTime Api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
how do i clear the keyboard buffer? i tried fflush(stdin) , _flushall(), nothing's working what could be the problem??
0x0400:
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
|
This looks like it will only purge one keyboard message. Shoudn't it be:
MSG msg;
while ( PeekMessage(&msg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE|PM_NOYIELD) );
Steve
|
|
|
|
|
|
oops! sorry hehe, i'm talking about console mode . in C.
for example, you get the input through scanf , after getting the inputs, it does some process (may it be a while-do),during the process if you make strokes in your keyboard, its gets accumulated in the Kb buffer, so after the process is over, it automatically types in the input for the next scanf , you get me now?.. i want to clear the buffer everytime before "scanningf!"
0x0400:
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
VivekuniQ wrote: ForumVisual C++
Subject:Re: keyboard buffer
Sender:VivekuniQ
Date:11:06 12 Jan '06
how do i clear the keyboard buffer?
what specific problem are you facing
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
please look at my reply to owner drawn
0x0400:
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
Holla,
I just migrated some code from VC6 to VC7. It compiled without any warnings or errors, with no changes made.
However, the size of the debug- and release-versions increased by a factor of 10. The release version, for example, was 2 MiB and is 20 MiB now.
I suspect that this is due to the templates in the source (I did not write it, so I cannot be sure) which supposedly were inflated during compilation.
Is there a way (compiler option or pragma) do prevent this code inflation from happening in VC7?
It works and all, but sending 20 Megs via E-Mail is quite a pain.
Thanks in advance.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
This is highly unusual. What libraries do you use? MFC, ATL, WTL, STL etc.
Regards,
Nish
|
|
|
|
|
Are you really sure that you had compiled in release ?!?
20mb gees, it is like all libs that microsoft has made has linked with your application.
-Prakash
|
|
|
|