Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

safe sprintf snprintf(3) considered harmful

Name: Anonymous 2008-09-30 14:21

You should use int _snprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format,... ); instead.

Name: Anonymous 2008-09-30 14:50

fuck off

Name: Anonymous 2008-09-30 16:18

Use an implementation function instead of the standard one?
no. see >>2

Name: Anonymous 2008-09-30 16:57

fuck off

Name: Anonymous 2008-09-30 17:11

I am OP
Yes, the idea is disgusting, but it's not only microsoft now, other people are adopting it as well. I thought we could have a nice discussion about how this is right or wrong.

Name: Anonymous 2008-09-30 18:25

>>5
Use string objects with length counts instead of null-terminated character sequences, thread over.

Name: Anonix developper 2008-09-30 18:53

>>6
STD AND C++ IS BLOAT DIG PIGDUSTING

Name: Anonymous 2008-09-30 19:17

>>7
Who said anything about C++?

Name: Anonymous 2008-09-30 19:37

>>8
u

Name: Anonymous 2008-09-30 19:40

>>9
no

Name: Anonymous 2008-09-30 20:00

>>7
STD is ridiculously streamlined and optimizes into almost nothing.  Enjoy your FAIL worldview.

Name: Anonymous 2008-09-30 20:23

>>11
Too bad it bloats the executable by four megabytes and degrades the performace by an order of two magnitudes.

Name: Anonymous 2008-09-30 20:32

>>12
If and only if you include the entire CRT in the executable as a static library.

Name: Anonymous 2008-09-30 20:32

>>11
ls -l /usr/lib/libstdc++.*

Name: Anonymous 2008-09-30 20:56

>>13
That's what I'd do if I was using my own library as well, except that it wouldn't have every component depend on every other.

Oh, and it'd be written in blazing fast C.

Name: Anonymous 2008-09-30 21:00

>>12,13
Welcome back to 1993. Don't worry, we'll eventually get better machines in ten years time.

Name: Anonymous 2008-09-30 21:00

>>14
SOU NAN DESS KARR?
-r--r--r--  1 root  wheel  1522998 Mar 12  2008 /usr/lib/libstdc++.a
-r--r--r--  1 root  wheel   956095 Nov 23  2007 /usr/lib/libstdc++.so.42.0
-r--r--r--  1 root  wheel   955948 Mar 12  2008 /usr/lib/libstdc++.so.44.0

Name: Anonymous 2008-10-01 2:26

>>15
C++ is faster than C, you fucking neo-luddite.  Get your head out of your Amish ass.

Name: Anonymous 2008-10-01 2:35

fuck all this talk of "safe" code, just check your input size if it's fixed, or use dynamically expanding buffers if it's not.

and if you can't prove an upper bound on the length of the data you're generating and supplying to sprintf, then you shouldn't be programming.

it's as simple as that.

Name: Anonymous 2008-10-01 2:47

>>18
7/10

Name: Anonymous 2008-10-01 4:31

>>20
0/10

C++ actually is faster.

Name: Anonymous 2008-10-01 4:43

>>21
Faster at trivial programs from shootout.alioth.debian.org that are not using most of c++ functionality except templates which are unsuited for large programs because of infinitely long compile times?

Name: Anonymous 2008-10-01 4:51

>>19
5/10
Obvious troll, exudes arrogance out of every orifice.

Name: Anonymous 2008-10-01 6:07

>>22
Fuck the shootout shit.  C++ is faster at function calls (due to having specific registers reserved for this instead of always lugging around explicit parameters), faster at anything dispatched than cobbled together C shit, and the template expansions from the STL libs have all sorts of really tight optimizations that you're not going to have in your "yet another shitty variable-size array" implementation.

Name: Anonymous 2008-10-01 6:41

>>24
9/10, almost got trolled.

How can C++ be faster at features C doesn't even have?

Name: Anonymous 2008-10-01 10:09

RAGE

Name: Anonymous 2008-10-01 11:24

Ok, that's it. The rating troll has gone too far. Stop fucking rating posts that aren't trolling.

Name: Anonymous 2008-10-01 11:34

>>24
What compiler does these ``really tight optimizations''?

Name: Anonymous 2008-10-01 11:49

>>28
g++

Name: Anonymous 2008-10-01 12:46

use -h with -l to avoid being off by an order of magnitude mistakes.

Name: Anonymous 2008-10-01 13:06

>>27
8/10

Name: Anonymous 2008-10-01 13:08

>>29
I googled for ``STL c++'', and found this program in the very first result:
#include <iostream>
#include <vector>
#include <string>

using namespace std;

main()
{
   vector<string> SS;

   SS.push_back("The number is 10");
   SS.push_back("The number is 20");
   SS.push_back("The number is 30");

   cout << "Loop by index:" << endl;

   int ii;
   for(ii=0; ii < SS.size(); ii++)
   {
      cout << SS[ii] << endl;
   }

   cout << endl << "Constant Iterator:" << endl;

   vector<string>::const_iterator cii;
   for(cii=SS.begin(); cii!=SS.end(); cii++)
   {
      cout << *cii << endl;
   }

   cout << endl << "Reverse Iterator:" << endl;

   vector<string>::reverse_iterator rii;
   for(rii=SS.rbegin(); rii!=SS.rend(); ++rii)
   {
      cout << *rii << endl;
   }

   cout << endl << "Sample Output:" << endl;

   cout << SS.size() << endl;
   cout << SS[2] << endl;

   swap(SS[0], SS[2]);
   cout << SS[2] << endl;
}


It outputs:
Loop by index:
The number is 10
The number is 20
The number is 30

Constant Iterator:
The number is 10
The number is 20
The number is 30

Reverse Iterator:
The number is 30
The number is 20
The number is 10

Sample Output:
3
The number is 30
The number is 10


I compiled it with g++ go.cpp -O3 -S -o go.S and uploaded result to pastebin: http://pastebin.com/m335e2398

Do you call this monstrosity really tight optimization?

Name: Anonymous 2008-10-01 13:36

>>32
You, sir, have been exponentially trolled.

Name: Anonymous 2008-10-01 14:02

>>33
Acting stupid does not equal trolling

Name: Anonymous 2008-10-01 14:43

>>32
You forgot to funroll your loops.

Name: Anonymous 2008-10-01 15:04

>>33
nlog(n) trolling is far from exponential.

Name: Anonymous 2008-10-01 15:10

>>35
That's not the point

Name: Anonymous 2008-10-01 18:25

>>25
How can C++ be faster at features C doesn't even have?
Because you're writing actual programs.  If the language doesn't support it, you generally end up making your own shitty version of stuff that other languages support much better.

in b4 Greenspun's 10th rule

Name: Anonymous 2008-10-01 23:22

>>38
Loot at 32, faggot

Name: Anonymous 2008-10-02 0:20

Unrelated: In >>32 main has omitted return type, which defaults to int in C. Isn't it not allowed in Sepples?

Name: Anonymous 2008-10-02 0:27

>>40
Correct, >>32 is malformed.

Name: Anonymous 2008-10-02 6:14

>>41
Ah, yeah. g++ starts complaining about it with -Wall.

Name: Anonymous 2008-10-02 13:54

Why does g++ not default to -Wall?

Name: Anonymous 2008-10-02 16:14

>>43
Who is John Galt?

Name: Anonymous 2008-10-02 16:19

>>43
Because EXPERT is the default programmer and he does not need nitpicky warnings.

Name: Anonymous 2009-09-17 15:19

Lain.

Name: Anonymous 2011-02-03 8:17

Don't change these.
Name: Email:
Entire Thread Thread List