473,405 Members | 2,310 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,405 software developers and data experts.

DATETIME like YYYYMMDDHHMMSS

Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)

Ferhat
Jul 22 '05 #1
55 9493

"Jazzhouse" <fe****@ventusvigor.com> wrote in message
news:cj***********@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it is
better to go with GCC... :)


You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C or
C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

john
Jul 22 '05 #2
John Harrison wrote:
"Jazzhouse" <fe****@ventusvigor.com> wrote in message
news:cj***********@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)


You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C or
C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

Which part of the above is C++?

--
WW aka Attila
:::
No trees were killed in the creation of this message. However, many
electrons were terrible inconvenienced.
Jul 22 '05 #3
White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
comp.lang.c++:
Which part of the above is C++?


#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4
Rob Williscroft wrote:
White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
comp.lang.c++:
Which part of the above is C++?


#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here and
there introducing the opportunity for buffer overruns. I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.

--
WW aka Attila
:::
Historically speaking, the presence of wheels in Unix has never precluded
their reinvention. - Larry Wall
Jul 22 '05 #5
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Rob Williscroft wrote:
White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
comp.lang.c++:
Which part of the above is C++?
#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here

and there introducing the opportunity for buffer overruns. I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Oh, Atilla, you are SO fussy!
--
Gary
Jul 22 '05 #6

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
John Harrison wrote:
"Jazzhouse" <fe****@ventusvigor.com> wrote in message
news:cj***********@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)


You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C or C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

Which part of the above is C++?


All of it. Remember that the C++ standard library contains
the (C90) C standard library. Also, tHe headers with .h, while
deprecated, are indeed part of standard C++.

-Mike
Jul 22 '05 #7

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Rob Williscroft wrote:
White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
comp.lang.c++:
Which part of the above is C++?
#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code.


which also qualifies as 'pure C++ code'.
Here and
there introducing the opportunity for buffer overruns.
That's a quality issue.
I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Call it what you like. It *is* C++, according to 14882.

-Mike
Jul 22 '05 #8
"Jazzhouse" <fe****@ventusvigor.com> wrote in message
news:cj***********@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)


Try:
#include <iostream>
#include <iomanip>
#include <ctime>

int main()
{
time_t t = time(0);
struct tm *lt = localtime(&t);
std::cout << std::setfill('0');
std::cout << std::setw(4) << lt->tm_year + 1900
<< std::setw(2) << lt->tm_mon + 1
<< std::setw(2) << lt->tm_mday
<< std::setw(2) << lt->tm_hour
<< std::setw(2) << lt->tm_min
<< std::setw(2) << lt->tm_sec
<< std::endl;
}
--
Gary
Jul 22 '05 #9
Starting with two deprecated headers and followed by pure C code.
which also qualifies as 'pure C++ code'.

int Blah()
{
return 5;
}

int main()
{
Blah(8);
}
Case and point.

C is irrelevant here.

Call it what you like. It *is* C++, according to 14882.

Just like a banger is still a car.
-JKop
Jul 22 '05 #10

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Rob Williscroft wrote:
White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
comp.lang.c++:
Which part of the above is C++?


#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here
and there introducing the opportunity for buffer overruns. I see. It is
code which compiles with a C++ compiler. I would not call it C++ code.


I see no buffer overflow before the year 10000. I don't care about that.

I was mainly trying to demonstrate to the OP that the same solution was
possible in C and C++ (he seemed concerned). But if you compare the partial
solution given by Gary Labowitz with mine I would still prefer the C like
solution above. Right tool for the right job I would say.

John
Jul 22 '05 #11
"John Harrison" <jo*************@hotmail.com> wrote in message
news:2s*************@uni-berlin.de...

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Rob Williscroft wrote:
White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
comp.lang.c++:

Which part of the above is C++?

#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.
Starting with two deprecated headers and followed by pure C code. Here
and there introducing the opportunity for buffer overruns. I see. It is code which compiles with a C++ compiler. I would not call it C++ code.


I see no buffer overflow before the year 10000. I don't care about that.

I was mainly trying to demonstrate to the OP that the same solution was
possible in C and C++ (he seemed concerned). But if you compare the

partial solution given by Gary Labowitz with mine I would still prefer the C like
solution above. Right tool for the right job I would say.


I've taught C, and I teach C++. There is not a mention of sprintf and printf
in my C++ courses. Why should there be?
I don't teach backward compatibility. I don't even like having to explain
why <ctime> is used instead of just <time>.
Since the languages have diverged, there is no sense to me in trying to keep
them together.
--
Gary
Jul 22 '05 #12
I've taught C, and I teach C++. There is not a mention of sprintf and
printf in my C++ courses. Why should there be?
I don't teach backward compatibility. I don't even like having to
explain why <ctime> is used instead of just <time>.
Since the languages have diverged, there is no sense to me in trying to
keep them together.

Preach!
-JKop

Jul 22 '05 #13

"Gary Labowitz" <gl*******@comcast.net> wrote in message
news:cv********************@comcast.com...
"John Harrison" <jo*************@hotmail.com> wrote in message
news:2s*************@uni-berlin.de...

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Rob Williscroft wrote:
> White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
> comp.lang.c++:
>
>> Which part of the above is C++?
>
> #include <time.h>
> #include <stdio.h>
>
> int main()
> {
> time_t t = time(0);
> struct tm* lt = localtime(&t);
> char time_str[15];
> sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
> lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
> lt->tm_hour, lt->tm_min, lt->tm_sec
> );
> printf( "%s\n", time_str );
> }
>
> All of it apparently.

Starting with two deprecated headers and followed by pure C code. Here and there introducing the opportunity for buffer overruns. I see. It is code which compiles with a C++ compiler. I would not call it C++ code.
I see no buffer overflow before the year 10000. I don't care about that.

I was mainly trying to demonstrate to the OP that the same solution was
possible in C and C++ (he seemed concerned). But if you compare the

partial
solution given by Gary Labowitz with mine I would still prefer the C like solution above. Right tool for the right job I would say.


I've taught C, and I teach C++. There is not a mention of sprintf and

printf in my C++ courses. Why should there be?
Well if it's your course it is up to you, and I can see why you would not
want to teach two methods of doing the same thing, so it makes perfect sense
not to teach sprintf etc. Nevertheless I still find sprintf useful for
certain situations.

1) The code is more compact when the formatting is complex, as it was in
this example.

2) With sprintf the format information is localised in a single string. This
can be useful when trying to write applications for different locales. Of
course C++ libraries exist with the same facility (e.g. boost format). The
very fact that boost format exists demonstrates that the approach taken by
sprintf is useful.

3) There is also considerably less overhead in sprintf than ostringstream. I
almost always prefer it to ostringstream when doing one off formatting tasks
like the OP's.
I don't teach backward compatibility. I don't even like having to explain
why <ctime> is used instead of just <time>.
Since the languages have diverged, there is no sense to me in trying to keep them together.


I'm not trying to keep anything together, just picking what I see as the
right tools for this particular task. Obviously it a judgement call, and
different people will choose different methods. I'm not trying to say my
method is the best, just that it is valid.

john
Jul 22 '05 #14
"John Harrison" <jo*************@hotmail.com> wrote in message
news:2s*************@uni-berlin.de...

"Gary Labowitz" <gl*******@comcast.net> wrote in message <<snip>> I'm not trying to keep anything together, just picking what I see as the
right tools for this particular task. Obviously it a judgement call, and
different people will choose different methods. I'm not trying to say my
method is the best, just that it is valid.


Thanks, John, it's a reasonable response.
Look, when I get a call to do some Access 2 work (and I did about a year
ago) I had to explain that I had long ago uninstalled that version and moved
on. The guy was very disappointed. I had a job updating a FoxPro program a
while back, and they wouldn't convert to Visual FoxPro. What they wanted was
virtually undoable and I told them so. I've been through the trauma of
learning enough new versions of languages to want to maintain lots of
versions --- in general I pick up the new version and move on. My current
internal debate is with VB6.0 and VB .NET. I have them both installed and I
hate like hell to give up VB 6.0. But I guess it will happen if I stick
around much longer.

I have always hated the languages that maintain lots of old version
constructs for backward compatibility. They don't want to break all the old
code, and you can't force people to upgrade all that software in a short
timeframe, but when? Microsoft puts the screws on by naming a date and
dropping support after that. It's cruel I guess, but otherwise they will
sink in a quagmire of versions. It's one of the worst aspects of computing.
Hard won knowledge is hard to let go of, and the new stuff can be very hard
to learn. Will we ever get rid of C-style strings in C++? Probably not. One
book I'm using now mentions them in an Appendix, that's how little they are
needed -- except for backwash I/O and old programs. I have to teach it, but
if you teach string class first they look like a real waste of time and
effort.

Well, I can cut and run (being over the age of sticking around). But what of
my students? They are graduating in years like 2006, 2008, and still
programming like it was 1991. I'm getting to hate it. [This is in the
category of "Don't get me started."]
--
Gary
Jul 22 '05 #15
Will we ever get rid of C-style
strings in C++? Probably not.

I don't see what's wrong with C-style strings. I use them 90% of the time,
unless I *need* an std::string. Why? Efficency.

A string is and always will be just an array of characters after all! As for
the whole null character thing... two possible methods:

A) Use a null character which signifies the end of the string, as in:

char blah[6] = { 'H', 'e', 'l', 'l', 'o', '\0' };
B) Have a field for the length of the string:

struct Blah
{
unsigned length;

char blah[5];
};

Blah poo = { 5, { 'H', 'e', 'l', 'l', 'o' } };
The former was chosen and it works well. It has advantages too: There's no
limit put on the length of the string, whereas with the latter, the length
is limited to the maximum value of an "unsigned".

As for std::string and std::ostringstream, I use them when want I want to do
would take me a few hours to code if I were to do it by myself, whereas it
would only take a few mins with these classes.

-JKop
Jul 22 '05 #16
Gary Labowitz wrote:
All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here
and there introducing the opportunity for buffer overruns. I see. It
is code which compiles with a C++ compiler. I would not call it C++
code.


Oh, Atilla, you are SO fussy!


Neither. I am Attila and I believe that in a C++ group pure C code should
be flagged as such. BTW the sig-quotes are REALLY random. Does my random
number device try to tell something? To whom? ;-)

--
WW aka Attila
:::
Never argue with an idiot. They drag you down to their level then beat you
with experience.
Jul 22 '05 #17
Mike Wahler wrote:
All of it apparently.


Starting with two deprecated headers and followed by pure C code.


which also qualifies as 'pure C++ code'.


I see. Do you not want to see the point?
Here and
there introducing the opportunity for buffer overruns.


That's a quality issue.


Is it? Or is it that code with C++ design is less likely to have that
problem?
I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Call it what you like. It *is* C++, according to 14882.


It is pure C. There is nothing C++ to it. You can call it whatever you
want, that won't change the facts.

--
WW aka Attila
:::
Man is a peculiar creature. He spends a fortune making his home
insect-proof and air-conditioned, and then eats in the yard.
Jul 22 '05 #18
I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Call it what you like. It *is* C++, according to 14882.


It is pure C. There is nothing C++ to it. You can call it whatever you
want, that won't change the facts.


What is this please?

int main()
{
return 0;
}

john
Jul 22 '05 #19
John Harrison wrote:
"White Wolf" <wo***@freemail.hu> wrote in message [SNIP]
All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here
and there introducing the opportunity for buffer overruns. I see. It
is code which compiles with a C++ compiler. I would not call it C++
code.


I see no buffer overflow before the year 10000. I don't care about that.


I see. I do, since I do not believe that this is the only way of failure
waiting there.
I was mainly trying to demonstrate to the OP that the same solution was
possible in C and C++ (he seemed concerned). But if you compare the
partial solution given by Gary Labowitz with mine I would still prefer
the C like solution above. Right tool for the right job I would say.


I have asked if it was a C++ solution. Later (having got the reply I did) I
hinted on it, that it had a buffer overflow opportunity. Prior to that all
I have been trying to point out is that it is C and not C++. Reason being
that we have tried for ages here to show C++ solutions or flag the pure C
solutions as such. Or tell (for dumb people like me) why is that C code the
best C++ to use.

--
WW aka Attila
:::
When the pupil is ready, the teacher will come.
Jul 22 '05 #20
Mike Wahler wrote:
[SNIP]
You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C
or C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

Which part of the above is C++?


All of it. Remember that the C++ standard library contains
the (C90) C standard library. Also, tHe headers with .h, while
deprecated, are indeed part of standard C++.


And it is still a pure C solution. IIRC there was an agreement here that
when showing code, we show C++ code and the best C++ there is to demonstrate
the issue. I see no problem with pure C code as long as it is proven that
that piece of code is the best C++ solution as well.

--
WW aka Attila
:::
Zen meditation isn't what you think...
Jul 22 '05 #21
> >
I see no buffer overflow before the year 10000. I don't care about that.
I see. I do, since I do not believe that this is the only way of failure
waiting there.


OK, educate me, where are the other oppotunites for buffer overflow?
I was mainly trying to demonstrate to the OP that the same solution was
possible in C and C++ (he seemed concerned). But if you compare the
partial solution given by Gary Labowitz with mine I would still prefer
the C like solution above. Right tool for the right job I would say.
I have asked if it was a C++ solution. Later (having got the reply I did)

I hinted on it, that it had a buffer overflow opportunity. Prior to that all I have been trying to point out is that it is C and not C++. Reason being
that we have tried for ages here to show C++ solutions or flag the pure C
solutions as such. Or tell (for dumb people like me) why is that C code the best C++ to use.


I did flag it as a C solution. Whether it is the best solution is obviously
a matter of opinion. I just coded what I would have done given the OP's
problem.

john
Jul 22 '05 #22

"JKop" <NU**@NULL.NULL> wrote in message
news:l6*******************@news.indigo.ie...
Starting with two deprecated headers and followed by pure C code.
which also qualifies as 'pure C++ code'.

int Blah()
{
return 5;
}

int main()
{
Blah(8);
}
Case and point.


What is your point? What you wrote above is *not* valid C++,
but is valid C (99).

C is irrelevant here.
It is relevant to "White Wolf"s remarks, since that was what
he talked about.

Call it what you like. It *is* C++, according to 14882.

Just like a banger is still a car.


I don't know what a 'banger' is. (I'll guess it's some
sort of 'slang', but 'slang' and informal terms imo should
be eschewed in a technical forum. It only leads to confusion.

-Mike
Jul 22 '05 #23

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
All of it apparently.

Starting with two deprecated headers and followed by pure C code.
which also qualifies as 'pure C++ code'.


I see. Do you not want to see the point?


Sure. So tell me what your point is.
Here and
there introducing the opportunity for buffer overruns.
That's a quality issue.


Is it?


Yes. The code is valid C++. Whether it's of 'good quality'
is of course a matter of opinion.
Or is it that code with C++ design is less likely to have that
problem?
What is "C++ design?".
I see. It is code
which compiles with a C++ compiler.

It is code which conforms to the internation standard which
defines the C++ language.
I would not call it C++ code.
The C++ standard does.

Call it what you like. It *is* C++, according to 14882.


It is pure C.


It qualifies as C and C++.
There is nothing C++ to it.
Everything in it is valid C++ according to the C++ standard.
You can call it whatever you
want, that won't change the facts.


That's right. And the facts are that is is valid C++.

-Mike
Jul 22 '05 #24

"Gary Labowitz" <gl*******@comcast.net> wrote in message
news:cv********************@comcast.com...
"John Harrison" <jo*************@hotmail.com> wrote in message
news:2s*************@uni-berlin.de...

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Rob Williscroft wrote:
> White Wolf wrote in news:cj**********@phys-news1.kolumbus.fi in
> comp.lang.c++:
>
>> Which part of the above is C++?
>
> #include <time.h>
> #include <stdio.h>
>
> int main()
> {
> time_t t = time(0);
> struct tm* lt = localtime(&t);
> char time_str[15];
> sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
> lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
> lt->tm_hour, lt->tm_min, lt->tm_sec
> );
> printf( "%s\n", time_str );
> }
>
> All of it apparently.

Starting with two deprecated headers and followed by pure C code. Here and there introducing the opportunity for buffer overruns. I see. It is code which compiles with a C++ compiler. I would not call it C++ code.
I see no buffer overflow before the year 10000. I don't care about that.

I was mainly trying to demonstrate to the OP that the same solution was
possible in C and C++ (he seemed concerned). But if you compare the

partial
solution given by Gary Labowitz with mine I would still prefer the C like solution above. Right tool for the right job I would say.


I've taught C, and I teach C++. There is not a mention of sprintf and

printf in my C++ courses. Why should there be?
That depends upon your teaching goals. However, for completeness,
perhaps you should at least mention that those functions exist in
C++, even if you don't actually teach about or use them in class.

I don't teach backward compatibility.
Backward compatibility is important in the 'real world'.
I don't even like having to explain
why <ctime> is used instead of just <time>.
I think you meant <time.h>. There is no <time> header in
either language.
Since the languages have diverged, there is no sense to me in trying to keep them together.


Many C++ projects interface with C code. One should be at least
aware of the facilities for dealing with this, even if it's not
part of a "C++ only" course.

$.02,
-Mike
Jul 22 '05 #25

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
[SNIP]
You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C
or C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code
Which part of the above is C++?
All of it. Remember that the C++ standard library contains
the (C90) C standard library. Also, tHe headers with .h, while
deprecated, are indeed part of standard C++.


And it is still a pure C solution.

It is a solution which qualifies as legal C *or* C++. Both
language standards support this assertion.
IIRC there was an agreement here that
when showing code, we show C++ code

Well, yes, this is a C++ group.
and the best C++ there is
"Best" will never be agreed upon, since it's a subjective issue.
to demonstrate
the issue.
John gave what he (apparently) felt was the 'best' solution.
What did he feel was 'best' about it? I'm not sure. Perhaps
as simple as that he thought it would be easier for OP to follow
that e.g. something involving containers etc.

I see no problem with pure C code
John's code qualifies according to both standards as C *or* C++.
If it were not valid C, it would not be topical here. So far
I haven't seen anyone challenge the topicality of his code (and
anyone who did would be wrong to do so(.
as long as it is proven that
that piece of code is the best C++ solution as well.


Again, "best" can never be proven. It's a matter of opinion,
and dependent upon context as well.
-Mike

Jul 22 '05 #26

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Gary Labowitz wrote:
All of it apparently.

Starting with two deprecated headers and followed by pure C code. Here
and there introducing the opportunity for buffer overruns. I see. It
is code which compiles with a C++ compiler. I would not call it C++
code.


Oh, Atilla, you are SO fussy!


Neither. I am Attila and I believe that in a C++ group pure C code should
be flagged as such.


I agree with that, and also add that it should be flagged as
off topic. However John's code does not qualify as such.

-Mike
Jul 22 '05 #27
Mike Wahler wrote in news:u7f8d.2569$M05.241
@newsread3.news.pas.earthlink.net in comp.lang.c++:
I don't even like having to explain
why <ctime> is used instead of just <time>.


I think you meant <time.h>. There is no <time> header in
either language.


That *is* the point, i.e. why is <ctime> not <time>.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #28

"Rob Williscroft" <rt*@freenet.co.uk> wrote in message
news:Xn**********************************@130.133. 1.4...
Mike Wahler wrote in news:u7f8d.2569$M05.241
@newsread3.news.pas.earthlink.net in comp.lang.c++:
I don't even like having to explain
why <ctime> is used instead of just <time>.


I think you meant <time.h>. There is no <time> header in
either language.


That *is* the point, i.e. why is <ctime> not <time>.


Because as far as I can tell, the 'c' in the name
is to denote that the header comes from the portion
of the C library inherited by the C++ library.

-Mike
Jul 22 '05 #29
White Wolf wrote:

I see. I do, since I do not believe that this is the only way of
failure waiting there.

If you see a problem, point it out. Don't just hint.

Brian Rodenborn
Jul 22 '05 #30
"White Wolf" <wo***@freemail.hu> wrote:
Mike Wahler wrote:
Here and
there introducing the opportunity for buffer overruns.


That's a quality issue.


Is it? Or is it that code with C++ design is less likely to have that
problem?


There is no opportunity for buffer overruns in the posted code
(assuming an implementation that conforms to the C++ standard,
of course)
I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Call it what you like. It *is* C++, according to 14882.


It is pure C. There is nothing C++ to it. You can call it whatever you
want, that won't change the facts.


Everything in it is C++. Have you read the C++ standard?
I'm not sure what your point is, but you seem to think
that C++ is a set of additions to C, and this code
does not use any of those additions? The truth is that
C++ is a language in its own right (which has tried to
remain as compatible with C as possible, even to the extent
that some text files constitute valid programs in both
languages).
Jul 22 '05 #31
"Gary Labowitz" <gl*******@comcast.net> wrote:
"John Harrison" <jo*************@hotmail.com> wrote:

"Gary Labowitz" <gl*******@comcast.net> wrote in message

<<snip>>
I'm not trying to keep anything together, just picking what I see as the
right tools for this particular task. Obviously it a judgement call, and
different people will choose different methods. I'm not trying to say my
method is the best, just that it is valid.


I have always hated the languages that maintain lots of old version
constructs for backward compatibility. They don't want to break all the old
code, and you can't force people to upgrade all that software in a short
timeframe, but when? Microsoft puts the screws on by naming a date and
dropping support after that. It's cruel I guess, but otherwise they will
sink in a quagmire of versions. It's one of the worst aspects of computing.


The difference is that C is well-designed and the Windows API
isn't (in comparison). It costs MS millions to maintain backwards
compatibility to those old versions whereas it doesn't cost
anything extra to write an ANSI C program. If they had the chance
to fix all the problems in C, then there would be very little
change (look at the spectactular success of VLAs, flexible struct
members, ...) C is still chosen ahead of a myriad of other languages
as the language for a new project. In fact Digital Mars D is the
closest I've seen to such a 'fix' and even that is not very dissimilar
to C (and although I don't know that language well, it wouldn't
surprise me if John Harrison's code was, or was almost exactly, valid D).
Jul 22 '05 #32
"Rob Williscroft" <rt*@freenet.co.uk> wrote in message
news:Xn**********************************@130.133. 1.4...
Mike Wahler wrote in news:u7f8d.2569$M05.241
@newsread3.news.pas.earthlink.net in comp.lang.c++:
I don't even like having to explain
why <ctime> is used instead of just <time>.


I think you meant <time.h>. There is no <time> header in
either language.


That *is* the point, i.e. why is <ctime> not <time>.


Thank you, Rob. Discussing <ctime> or <cmath> ends up mentioning <time.h>
and <math.h>. Indeed, we use the Dev-C++ IDE and it invokes MinGW. The
<cmath> file (and it is a file in MinGW) simply #include's <math.h>. If I
start explaining this it leads to discussion of headers files vs. headers,
and what all that implies. If I start on this sort of thing with the
beginning students their eyes spin a little and they shut down. I hate to
see that happen.

All languages are so complex that you cannot learn them ALL_AT_ONCE. They
must have a "baby talk" stage, and add onto that. It's very difficult to
select what goes in the baby talk and what waits until later. Remember, some
learners aren't all that solid with concepts like copying files, much less
easily accepting of passing by reference. I like to think I make it easier
by lying to them at first and then, when they can program in baby talk,
explain the subtleties.

Of course, I may be wrong. We don't mention struct's or classes until second
semester course either. Sometimes I think it would be smarter teaching
classes right out of the box. It would make it easier to start them with
<string>, etc. and introduce c-style strings later as we do now in the
Appendix.

It's hard teaching a language when the only correct information about it are
in an encyclopedia and a dictionary. [And some text that a committee selects
because it looks beautiful but is actually inaccurate and misleading.] And
when the newbie comes to the ng and asks a question about some simple
element of the language he often gets (among other things) direction on how
he should use templated classes instead of a simple answer to his question.
I cringe at those helpful souls' answers.
--
Gary


Jul 22 '05 #33
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Gary Labowitz wrote:
> All of it apparently.

Starting with two deprecated headers and followed by pure C code.
Here and there introducing the opportunity for buffer overruns. I
see. It is code which compiles with a C++ compiler. I would not
call it C++ code.

Oh, Atilla, you are SO fussy!


Neither. I am Attila and I believe that in a C++ group pure C code
should be flagged as such.


I agree with that, and also add that it should be flagged as
off topic. However John's code does not qualify as such.


So Mr John's code does not compile on a C compiler? What a surprise...

--
WW aka Attila
:::
Great minds discuss ideas. Average minds discuss events. Small minds
discuss people.
Jul 22 '05 #34
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
> All of it apparently.

Starting with two deprecated headers and followed by pure C code.

which also qualifies as 'pure C++ code'.


I see. Do you not want to see the point?


Sure. So tell me what your point is.

I did about 5 times.
Here and
there introducing the opportunity for buffer overruns.

That's a quality issue.


Is it?


Yes. The code is valid C++. Whether it's of 'good quality'
is of course a matter of opinion.


Nowhere I said it is not valid C++. Obfuscated C is valid C as well.
Or is it that code with C++ design is less likely to have that
problem?


What is "C++ design?".


You are joking.
I see. It is code
which compiles with a C++ compiler.
It is code which conforms to the internation standard which
defines the C++ language.
I would not call it C++ code.


The C++ standard does.


Nope. Please show me wher does the C++ standard contain theabove code
verbatim and calls it the best C++ design.
Call it what you like. It *is* C++, according to 14882.


It is pure C.


It qualifies as C and C++.


Yes. Which means it is pure C, as long as it menas the same in C++ and C.
There is nothing C++ to it.


Everything in it is valid C++ according to the C++ standard.


And yet, there is nothing C++ to it.
You can call it whatever you
want, that won't change the facts.


That's right. And the facts are that is is valid C++.


The fact is, that it is pure C code, which happens ot be valid C++ code.
And yet, that does not make it good C++ code.

--
WW aka Attila
:::
Hard work spotlights the character of people; some turn up their sleeves,
some turn up their noses, and some don't turn up at all!
Jul 22 '05 #35
Old Wolf wrote:
"White Wolf" <wo***@freemail.hu> wrote:
Mike Wahler wrote:
Here and
there introducing the opportunity for buffer overruns.

That's a quality issue.
Is it? Or is it that code with C++ design is less likely to have that
problem?


There is no opportunity for buffer overruns in the posted code
(assuming an implementation that conforms to the C++ standard,
of course)


I see. Using sprintf, on a limited size buffer and there is no opportunity
of buffer overflow. Which C++ standard? Todays? 5 years from now? 50
years from now?
I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.

Call it what you like. It *is* C++, according to 14882.


It is pure C. There is nothing C++ to it. You can call it whatever you
want, that won't change the facts.


Everything in it is C++. Have you read the C++ standard?


Have you? I did not read it all. But hey, see you in Redmond and you can
explain to me what did I miss.
I'm not sure what your point is, but you seem to think
that C++ is a set of additions to C, and this code
does not use any of those additions?
C++ is *not* a set of additions to C.
The truth is that
C++ is a language in its own right (which has tried to
remain as compatible with C as possible, even to the extent
that some text files constitute valid programs in both
languages).


Yes. And that is why a pure C code needs explanation, telling why is it
posted to a C++ group. It may be the best C++ implementation possible. It
may not. But many people work on getting people to do C++ programming in
C++, and it does not do any justice to their work if others post pure C code
as C++. I can undertstand if someone prefers pure C, because it is a
library routine he wants both for C and C++. There may be many other
answers. But the answer which says, yeah it is also C++, is the wrong
answer. It sounds a lot like: Why did I do it? Because I could.

--
WW aka Attila
:::
Particle physicists are always trying to hold a meeting, but whenever they
decide on a place, the time changes.
Jul 22 '05 #36

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Gary Labowitz wrote:
>> All of it apparently.
>
> Starting with two deprecated headers and followed by pure C code.
> Here and there introducing the opportunity for buffer overruns. I
> see. It is code which compiles with a C++ compiler. I would not
> call it C++ code.

Oh, Atilla, you are SO fussy!

Neither. I am Attila and I believe that in a C++ group pure C code
should be flagged as such.


I agree with that, and also add that it should be flagged as
off topic. However John's code does not qualify as such.


So Mr John's code does not compile on a C compiler? What a surprise...


I 'misspoke' on this. I meant it doesn't qualify as "C but not C++".

-Mike
Jul 22 '05 #37

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
>> All of it apparently.
>
> Starting with two deprecated headers and followed by pure C code.

which also qualifies as 'pure C++ code'.

I see. Do you not want to see the point?
Sure. So tell me what your point is.

I did about 5 times.


So perhaps I'm dense. :-)
> Here and
> there introducing the opportunity for buffer overruns.

That's a quality issue.

Is it?
Yes. The code is valid C++. Whether it's of 'good quality'
is of course a matter of opinion.


Nowhere I said it is not valid C++. Obfuscated C is valid C as well.


You did say, and I quote you:

"> >> I would not call it C++ code."

Or is it that code with C++ design is less likely to have that
problem?
What is "C++ design?".


You are joking.


Not at all. C++ is a language. Design is design, regardless
of language.
> I see. It is code
> which compiles with a C++ compiler.
It is code which conforms to the internation standard which
defines the C++ language.
I would not call it C++ code.

See, here's what you said.


The C++ standard does.


Nope.


Yes. According to 14882, John's code is valid C++.
Please show me wher does the C++ standard contain theabove code
verbatim
I never said it did.
and calls it the best C++ design.
I never said it did. All I said was that the code is valid
C++.
Call it what you like. It *is* C++, according to 14882.

It is pure C.
It qualifies as C and C++.


Yes. Which means it is pure C,


It is equally 'pure C++'.
as long as it menas the same in C++ and C.
The meaning has nothing to do with it.
There is nothing C++ to it.
Everything in it is valid C++ according to the C++ standard.


And yet, there is nothing C++ to it.


Every part of it is C++ (and also happens to be C).
You can call it whatever you
want, that won't change the facts.


That's right. And the facts are that is is valid C++.


The fact is, that it is pure C code, which happens ot be valid C++ code.
And yet, that does not make it good C++ code.


I specifically stated that I was not talking about code quality,
only validity according to the C++ standard.

-Mike
Jul 22 '05 #38
White Wolf wrote:
Mike Wahler wrote:
I would not call it C++ code.


The C++ standard does.


Nope. Please show me wher does the C++ standard contain theabove code
verbatim and calls it the best C++ design.


So by your definition only code that can be found in verbatim in the C++
standard and what the C++ standard explicitly states to be the best "C++
design" can be considered C++ code? Interesting definition, but that
leaves very few code that can be considered C++. In fact I don't
remember reading anywhere in the C++ standard about code considered to
be the best "C++ design". Could you tell in which paragraphs of the C++
standard statements like this are made?

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 22 '05 #39
Mike Wahler wrote:

I did about 5 times.


So perhaps I'm dense. :-)


I am not qualified to decide that.
Nowhere I said it is not valid C++. Obfuscated C is valid C as well.


You did say, and I quote you:

"> >> I would not call it C++ code."


And which word of the above don't you understand? Especially pointing out
where does it talked about vailidity.
Or is it that code with C++ design is less likely to have that
problem?

What is "C++ design?".


You are joking.


Not at all. C++ is a language. Design is design, regardless
of language.


Oh boy. You used to be a reasonable person.
>> I see. It is code
>> which compiles with a C++ compiler.

It is code which conforms to the internation standard which
defines the C++ language.

I would not call it C++ code.
See, here's what you said.


Which isn't what you have implied I said.
The C++ standard does.


Nope.


Yes. According to 14882, John's code is valid C++.


Valid as C++, but it is C.
Please show me wher does the C++ standard contain theabove code
verbatim


I never said it did.


You did:
I would not call it C++ code.


The C++ standard does.

and calls it the best C++ design.


I never said it did. All I said was that the code is valid
C++.


And what I said is that I would not call it C++. So?
> Call it what you like. It *is* C++, according to 14882.

It is pure C.

It qualifies as C and C++.


Yes. Which means it is pure C,


It is equally 'pure C++'.


And yet, it is pure C.
as long as it menas the same in C++ and C.


The meaning has nothing to do with it.


Do you have your "disagreement" bit stuck?
There is nothing C++ to it.

Everything in it is valid C++ according to the C++ standard.


And yet, there is nothing C++ to it.


Every part of it is C++ (and also happens to be C).


What is C, is C. And it may happen to compile as C++ (according to the
standard). It may even do the same thing as in C, when compiled with a C++
compiler. Yet, it is C.
You can call it whatever you
want, that won't change the facts.

That's right. And the facts are that is is valid C++.


The fact is, that it is pure C code, which happens ot be valid C++
code. And yet, that does not make it good C++ code.


I specifically stated that I was not talking about code quality,
only validity according to the C++ standard.


And I have specifically stated that I was talking about one quality of that
code: that it is C code.

--
Attila aka WW
Jul 22 '05 #40
Peter van Merkerk wrote:
White Wolf wrote:
Mike Wahler wrote:
I would not call it C++ code.

The C++ standard does.
Nope. Please show me wher does the C++ standard contain theabove
code verbatim and calls it the best C++ design.


So by your definition only code that can be found in verbatim in the
C++ standard and what the C++ standard explicitly states to be the
best "C++ design" can be considered C++ code?


Please quote me where I say that.
Interesting definition,
You made it.
but that leaves very few code that can be considered C++.
Well, so why did you make it.
In fact I
don't remember reading anywhere in the C++ standard about code
considered to be the best "C++ design".
Nope. Neither did I say you did or even that it does contain it. But I bet
you did read it elsewhere.
Could you tell in which
paragraphs of the C++ standard statements like this are made?


The first such artifact - produced by WG21 -, which talks about programming
and not the programming language is the Perfomance TR. So to answer you:
most probably none.

As whole the whole thread of attacks on me. I have tried to point out that
the given code was pure C. Which (at some time) was the normal thing to do
here, but those who posted the code. I have never stated that it does not
compile with a C++ compiler. But since C++ maintains a CLOSE compatibility
with C, I doubt that it should be a surprise that C code compiles as C++,
and for most it does the same thing.

I always am amazed how offensive people can get and how much they disregard
the other opinion... with minor issues. The issue is LONG time solved. I
have tested a little that how long (even Mike, who used to be immune) can
people go on without realizing that what I am talking about is not what they
talk about. How long are they going to defend a design as C++ while it is
clearly a C design. Long. Too long for me. So me bail out.

--
Attila aka WW
Jul 22 '05 #41
Attila Feher wrote:
Peter van Merkerk wrote:
White Wolf wrote:
Mike Wahler wrote:

>I would not call it C++ code.

The C++ standard does.

Nope. Please show me wher does the C++ standard contain theabove
code verbatim and calls it the best C++ design.


So by your definition only code that can be found in verbatim in the
C++ standard and what the C++ standard explicitly states to be the
best "C++ design" can be considered C++ code?


Please quote me where I say that.


See above...

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 22 '05 #42
Peter van Merkerk wrote:
Attila Feher wrote:
Peter van Merkerk wrote:
White Wolf wrote:

Mike Wahler wrote:

>> I would not call it C++ code.
>
> The C++ standard does.

Nope. Please show me wher does the C++ standard contain theabove
code verbatim and calls it the best C++ design.

So by your definition only code that can be found in verbatim in the
C++ standard and what the C++ standard explicitly states to be the
best "C++ design" can be considered C++ code?


Please quote me where I say that.


See above...


I see no definition. And I see you have got to the stage where you do not
even read the post, only to the point of possible disagreement. Then what
for?

--
Attila aka WW
Jul 22 '05 #43

"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:cj**********@newstree.wise.edt.ericsson.se...
Mike Wahler wrote:

I did about 5 times.
So perhaps I'm dense. :-)


I am not qualified to decide that.
Nowhere I said it is not valid C++. Obfuscated C is valid C as well.


You did say, and I quote you:

"> >> I would not call it C++ code."


And which word of the above don't you understand?


I believe I understand it. You don't call it C++ code.
Yet it is. It's is C++ (and C).
Especially pointing out
where does it talked about vailidity.
Validity (of the code as C++) is what I'm talking about.
> Or is it that code with C++ design is less likely to have that
> problem?

What is "C++ design?".

You are joking.
Not at all. C++ is a language. Design is design, regardless
of language.


Oh boy. You used to be a reasonable person.


As did you. :-)
>>> I see. It is code
>>> which compiles with a C++ compiler.

It is code which conforms to the internation standard which
defines the C++ language.

> I would not call it C++ code.
See, here's what you said.


Which isn't what you have implied I said.


I didn't imply anything. I simply quoted you.
The C++ standard does.

Nope.
Yes. According to 14882, John's code is valid C++.


Valid as C++, but it is C.


It is *both*. That's is my point.
Please show me wher does the C++ standard contain theabove code
verbatim
I never said it did.


You did:
I would not call it C++ code.


The C++ standard does.

and calls it the best C++ design.


I never said it did. All I said was that the code is valid
C++.


And what I said is that I would not call it C++. So?


So it *is* C++ (and C).
>> Call it what you like. It *is* C++, according to 14882.
>
> It is pure C.

It qualifies as C and C++.

Yes. Which means it is pure C,
It is equally 'pure C++'.


And yet, it is pure C.


And it is also pure C++.
as long as it menas the same in C++ and C.
The meaning has nothing to do with it.


Do you have your "disagreement" bit stuck?


As stuck as yours. :-)
> There is nothing C++ to it.

Everything in it is valid C++ according to the C++ standard.

And yet, there is nothing C++ to it.
Every part of it is C++ (and also happens to be C).


What is C, is C.


Yes. And quite a bit of C code also qualifies as C++.
And it may happen to compile as C++ (according to the
standard). It may even do the same thing as in C, when compiled with a C++ compiler. Yet, it is C.
As well as C++.
> You can call it whatever you
> want, that won't change the facts.

That's right. And the facts are that is is valid C++.

The fact is, that it is pure C code, which happens ot be valid C++
code. And yet, that does not make it good C++ code.
I specifically stated that I was not talking about code quality,
only validity according to the C++ standard.


And I have specifically stated that I was talking about one quality of

that code: that it is C code.


But that assessment is incomplete. Is is also equally valid C++ code.
You mentioned 'quality' a while back. I already responded that 'quality'
is not part of my argument.

-Mike
Jul 22 '05 #44
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Gary Labowitz wrote:
>>> All of it apparently.
>>
>> Starting with two deprecated headers and followed by pure C code.
>> Here and there introducing the opportunity for buffer overruns. I
>> see. It is code which compiles with a C++ compiler. I would not
>> call it C++ code.
>
> Oh, Atilla, you are SO fussy!

Neither. I am Attila and I believe that in a C++ group pure C code
should be flagged as such.

I agree with that, and also add that it should be flagged as
off topic. However John's code does not qualify as such.


So Mr John's code does not compile on a C compiler? What a surprise...


I 'misspoke' on this. I meant it doesn't qualify as "C but not C++".


I love these random quotes...

I did not mean it will not compile on a C++ compiler. I guess when I say
C++ code (in the realm of this NG) I mean a bit more(*) "than just code
well-formed code which does not invoke undefined behavior and implementation
defined behavior which may alter its meaning".

(*) It more on contraints, so less code qualifies as C++ with that
definition.

--
WW aka Attila
:::
BTW, FWIW, IMHO, AFAIK, yes. OTOH, AAMOF, maybe not. YMMV.
Jul 22 '05 #45

"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:cj**********@newstree.wise.edt.ericsson.se...
Peter van Merkerk wrote:
White Wolf wrote:
Mike Wahler wrote:
> I would not call it C++ code.

The C++ standard does.

Nope. Please show me wher does the C++ standard contain theabove
code verbatim and calls it the best C++ design.
So by your definition only code that can be found in verbatim in the
C++ standard and what the C++ standard explicitly states to be the
best "C++ design" can be considered C++ code?


Please quote me where I say that.
Interesting definition,


You made it.
but that leaves very few code that can be considered C++.


Well, so why did you make it.
In fact I
don't remember reading anywhere in the C++ standard about code
considered to be the best "C++ design".


Nope. Neither did I say you did or even that it does contain it. But I

bet you did read it elsewhere.
Could you tell in which
paragraphs of the C++ standard statements like this are made?
The first such artifact - produced by WG21 -, which talks about

programming and not the programming language is the Perfomance TR. So to answer you:
most probably none.

As whole the whole thread of attacks on me.
I won't presume to speak for others, but please not that I
have *never* attacked *you*, only your ideas. There's a
big difference. I do respect you as a person, but I disagree
with your statements (this time, usually we've seemed to agree
in the past).
I have tried to point out that
the given code was pure C.
It is equally pure C++.
Which (at some time) was the normal thing to do
here, but those who posted the code. I have never stated that it does not
compile with a C++ compiler.
Which to me is an admission that it is indeed C++ code.
But since C++ maintains a CLOSE compatibility
with C, I doubt that it should be a surprise that C code compiles as C++,
Some does, some does not.
and for most it does the same thing.
Sometimes it will, other times not.

I always am amazed how offensive people can get
If you feel that disagreements about your ideas is 'offensive',
I cannot help that. My intention is simply to debate your ideas,
not to offend you or anyone.

and how much they disregard
the other opinion...
If I disregarded your opinion, I would not be debating it.
with minor issues. The issue is LONG time solved. I
have tested a little that how long (even Mike, who used to be immune) can
people go on without realizing that what I am talking about is not what they talk about.
Perhaps I am indeed misunderstanding you, but so far I don't think so.
How long are they going to defend a design

Design does not enter into my arguments. Only the validity of
a piece of code with regard to 14882. Poor (or good) design
can be done in any language.
as C++ while it is
clearly a C design.
The term "C design" (or _insert_language_here design) is meaningless
to me.
Long. Too long for me. So me bail out.


Me too. We're accomplishing nothing with this debate.
Again, I'm not attacking you, just these particular
opinions of yours. Let's move on to something else,
shall we?

-Mike
Jul 22 '05 #46
Mike Wahler wrote:
"> >> I would not call it C++ code."


And which word of the above don't you understand?


I believe I understand it. You don't call it C++ code.
Yet it is. It's is C++ (and C).


It being C what makes it valid C++, not it being C++. I cannot explain it
any better.
Especially pointing out
where does it talked about vailidity.


Validity (of the code as C++) is what I'm talking about.


Yep. I understand. But that is not what I was talking about when you have
chosen to contradict me, without trying to understand what I mean - which is
rather unusual from you.
>> Or is it that code with C++ design is less likely to have that
>> problem?
>
> What is "C++ design?".

You are joking.

Not at all. C++ is a language. Design is design, regardless
of language.


Oh boy. You used to be a reasonable person.


As did you. :-)


I had a filter installed, but my licence expired. ;-)
>>>> I see. It is code
>>>> which compiles with a C++ compiler.
>
> It is code which conforms to the internation standard which
> defines the C++ language.
>
>> I would not call it C++ code.

See, here's what you said.


Which isn't what you have implied I said.


I didn't imply anything. I simply quoted you.


You implied, that when I say "I would not call it C++" I mean that it is not
according to the C++ standard. Which I have clearly(?) and already 50 times
repeatedly explained that it is not so. Can I lift 150 kilograms? No.
Does it mean it is impossible? No. In this context, in this newsgroup, I
make a strict difference between code which uses C++ style and idioms and
code which does not, for example which is pure C.
> The C++ standard does.

Nope.

Yes. According to 14882, John's code is valid C++.


Valid as C++, but it is C.


It is *both*. That's is my point.


Mine too. Except that I am not surprised, as most of C is a subset of C++.
Therefore what I say is that the standard calls it C++ not because it is
C++, but because it is C. And the standard keeps compatibility with C -
where possible.
and calls it the best C++ design.

I never said it did. All I said was that the code is valid
C++.


And what I said is that I would not call it C++. So?


So it *is* C++ (and C).


It is C, which happens to also be C++. Stress on the first part of the
sentence.
>>> Call it what you like. It *is* C++, according to 14882.
>>
>> It is pure C.
>
> It qualifies as C and C++.

Yes. Which means it is pure C,

It is equally 'pure C++'.


And yet, it is pure C.


And it is also pure C++.


Because it is C, and not because it is C++.
as long as it menas the same in C++ and C.

The meaning has nothing to do with it.


Do you have your "disagreement" bit stuck?


As stuck as yours. :-)


I completely agree with myself. ;-)
>> There is nothing C++ to it.
>
> Everything in it is valid C++ according to the C++ standard.

And yet, there is nothing C++ to it.

Every part of it is C++ (and also happens to be C).


What is C, is C.


Yes. And quite a bit of C code also qualifies as C++.


The reason not being because it is C++, but because it is C.
And it may happen to compile as C++ (according to the
standard). It may even do the same thing as in C, when compiled with a
C++ compiler. Yet, it is C.


As well as C++.


Which stems from the fact that it is C. Nothing makes it more C++ than C.
Being C is the root of it being C++.
>> You can call it whatever you
>> want, that won't change the facts.
>
> That's right. And the facts are that is is valid C++.

The fact is, that it is pure C code, which happens ot be valid C++
code. And yet, that does not make it good C++ code.

I specifically stated that I was not talking about code quality,
only validity according to the C++ standard.


And I have specifically stated that I was talking about one quality of
that code: that it is C code.


But that assessment is incomplete. Is is also equally valid C++ code.
You mentioned 'quality' a while back. I already responded that 'quality'
is not part of my argument.


But that was the point of mine, to which you have originally reacted to.

Would I be shorter and had I more oil companies, I could be US president.

--
WW aka Attila
:::
The 50-50-90 rule: Any time you have a 50-50 chance of getting something
right, there's a 90% probability you'll get it wrong.
Jul 22 '05 #47

"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
Mike Wahler wrote:
"White Wolf" <wo***@freemail.hu> wrote in message
news:cj**********@phys-news1.kolumbus.fi...
> Gary Labowitz wrote:
>>>> All of it apparently.
>>>
>>> Starting with two deprecated headers and followed by pure C code.
>>> Here and there introducing the opportunity for buffer overruns. I
>>> see. It is code which compiles with a C++ compiler. I would not
>>> call it C++ code.
>>
>> Oh, Atilla, you are SO fussy!
>
> Neither. I am Attila and I believe that in a C++ group pure C code
> should be flagged as such.

I agree with that, and also add that it should be flagged as
off topic. However John's code does not qualify as such.

So Mr John's code does not compile on a C compiler? What a surprise...
I 'misspoke' on this. I meant it doesn't qualify as "C but not C++".


I love these random quotes...

I did not mean it will not compile on a C++ compiler. I guess when I say
C++ code (in the realm of this NG) I mean a bit more(*) "than just code
well-formed code which does not invoke undefined behavior and

implementation defined behavior which may alter its meaning".

(*) It more on contraints, so less code qualifies as C++ with that
definition.


So here's the crux: our definitions of what C++ is differs.
My meaning is: "does not violate requirements or constraints
imposed by 14882). Iterestingly, this does not preclude
syntactically correct code which produces undefined behavior.
Such code *is* C++, although it's certainly not 'good' code.

-Mike
Jul 22 '05 #48
Mike Wahler wrote:
As whole the whole thread of attacks on me.


I won't presume to speak for others, but please not that I
have *never* attacked *you*, only your ideas. There's a
big difference. I do respect you as a person, but I disagree
with your statements (this time, usually we've seemed to agree
in the past).


That part was somehow garbled beyond recognition.
I have tried to point out that
the given code was pure C.


It is equally pure C++.


Because it is C.
Which (at some time) was the normal thing to do
here, but those who posted the code. I have never stated that it does
not compile with a C++ compiler.


Which to me is an admission that it is indeed C++ code.


Again, you take a different definition to what is C++ that what I do. Since
C (mostly) is a subset of C++ most C code will qualify as C++. And yet, it
won't be what should be taught as C++ to beginners.
But since C++ maintains a CLOSE compatibility
with C, I doubt that it should be a surprise that C code compiles as
C++,


Some does, some does not.


OK, double that that.
and for most it does the same thing.


Sometimes it will, other times not.

Most I said, not all.
I always am amazed how offensive people can get


If you feel that disagreements about your ideas is 'offensive',
I cannot help that. My intention is simply to debate your ideas,
not to offend you or anyone.


Yeah. I fell that I should really learn the difference between offensive
and defensive... Which is of course what I wanted to write. Welcome to the
nightmares of someone not from an Indogerman language nation...
and how much they disregard
the other opinion...


If I disregarded your opinion, I would not be debating it.


Actually the trouble is that you debate yours. So far we have not discussed
my opinion, altough I have tried to bring it back to focus few million
times. :-)
with minor issues. The issue is LONG time solved. I
have tested a little that how long (even Mike, who used to be immune)
can people go on without realizing that what I am talking about is not
what they talk about.


Perhaps I am indeed misunderstanding you, but so far I don't think so.


And I cannot help about that.
How long are they going to defend a design


Design does not enter into my arguments. Only the validity of
a piece of code with regard to 14882. Poor (or good) design
can be done in any language.


And yet, there is code which one calls C design and there is code which one
calls C++ design. And since this isn't comp.std.c++ I am afraid that we
shall we talk about the /use/ of the language as well as its meaning (or
standard).
as C++ while it is
clearly a C design.


The term "C design" (or _insert_language_here design) is meaningless
to me.


Again, I feel that bit stuck.
Long. Too long for me. So me bail out.


Me too. We're accomplishing nothing with this debate.
Again, I'm not attacking you, just these particular
opinions of yours. Let's move on to something else,
shall we?

Unfortunately it is not a debate. :-( You are talking about something
completely different than I do.

--
WW aka Attila
:::
'Experience is a hard teacher because she gives the test first, the lesson
afterward.' --Vernon Law
Jul 22 '05 #49
Mike Wahler wrote:
I did not mean it will not compile on a C++ compiler. I guess when I
say C++ code (in the realm of this NG) I mean a bit more(*) "than just
code well-formed code which does not invoke undefined behavior and
implementation defined behavior which may alter its meaning".

(*) It more on contraints, so less code qualifies as C++ with that
definition.


So here's the crux: our definitions of what C++ is differs.
My meaning is: "does not violate requirements or constraints
imposed by 14882). Iterestingly, this does not preclude
syntactically correct code which produces undefined behavior.
Such code *is* C++, although it's certainly not 'good' code.


Useless C++, yes. But aren't we here to discuss useful ideas, and ideas
which (if necessary/possible) use the full power of the language?

--
WW aka Attila
:::
A self-addressed envelope would be addressed 'envelope'.
Jul 22 '05 #50

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

Similar topics

3
by: Martin Bless | last post by:
Below is what I'm currently using to construct datatime objects from strings. Date and time objects are made up similar. To and from string conversions are frequently needed in SQL neighborhood. ...
4
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it...
6
by: Thomas Bartkus | last post by:
MySQL Version 4.0.20 on a Linux server. How does one get the elapsed time between (2) DateTime values? I need the answer to the nearest minute. Is upgrading to Ver 5 with its more robust...
4
by: Mark | last post by:
Is there a way to convert a char to a DateTime without first converting to a string and using DateTime.Parse or ParseExact? I'm trying to reuse the char which can be reused instead of converting...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
1
by: Frank Esser | last post by:
Hello, how can I get the date/time value from a string that contains the date and time in this format: YYYYMMDDhhmmss Thanks!
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
3
by: Eric Stott | last post by:
I need to take System.DateTime.Now and have the resulting text be in the following format: yyyyMMddhh24mmsss I am using System.Convert.ToString(System.DateTime.Now), but I need to format it...
4
by: simonZ | last post by:
I have string 20070502144551 and I would like to convert this to datetime: 2007-05-02 14:45:51 Is there some function? Regards,Simon
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.