0
$\begingroup$

Why C is still in use especially in area of numerical optimization (instead of C++) ? C and C++ aren't fully compatible so mayby you know some differances that make the difference ?

$\endgroup$
7
  • 4
    $\begingroup$ Ugh, I wish I had seen this question earlier so I could close it. Too late now since enough people have chimed in. But I swear if this shows up on Hacker News or some garbage like that, I will burniate this. $\endgroup$ Feb 27, 2013 at 3:25
  • 4
    $\begingroup$ Feel free to close it. There is no value-added; same question has been asked a bazillion times already... $\endgroup$ Feb 27, 2013 at 3:35
  • 2
    $\begingroup$ People voting for this obviously derive value. And why would it be too late to close it if the same question was asked already? Ironically if the question was about R or Matlab I do not think we would see above comments. $\endgroup$
    – Matt Wolf
    Feb 27, 2013 at 8:35
  • $\begingroup$ In such a general form it fits Computational Science much more than here $\endgroup$ Feb 27, 2013 at 11:06
  • $\begingroup$ @AlexeyKalmykov They aren't going to want it either. Nor would Stack Overflow or Programmers.SE take it. It's just a really awful question. $\endgroup$ Feb 27, 2013 at 12:16

3 Answers 3

5
$\begingroup$

C is not used for any particular reason in numerical optimizations other than for legacy reasons. However, there are areas where C is preferred over C++ though even C is not the preferred language of choice. To mind comes programming FPGAs. Though VHDL and Verilog are by far the standards. But "behavioral synthesis" allows to utilize C or C relatives such as SystemC to transfer logic to HDL. In that C is the preferred choice over C++. (Though having started working with FPGAs I start to get the sense that VHDL and Verilog are so popular for good reasons; even though the learning curve is a lot steeper they are much closer to the core of the particular hardware logic (Gate Arrays have a vastly different structure than a CPU).

So, C has its applications and is the preferred choice of weapon in some areas but more often than not people prefer using what they are best at. At least in numerical optimization I do not see a single reason why C would be preferred over C++ and actually I doubt such claim.

$\endgroup$
6
  • 1
    $\begingroup$ FPGA's might not be a good fit for certain numerical optimization problems $\endgroup$
    – pyCthon
    Feb 27, 2013 at 2:33
  • 1
    $\begingroup$ @pyCthon, that was not my point, the point was to show an example in where it makes sense to have C be the preferred language over C++ and to explain why it is that case. By the way, as you already touched on it, FPGAs might not but can be an excellent fit for solving optimization problems. $\endgroup$
    – Matt Wolf
    Feb 27, 2013 at 3:03
  • $\begingroup$ I understand what you said pyCthon in fact when you need I/O you must think in a CPU like RISC. FGPA runs the whole application in one clock cycle. to create complex applications (eg to calculate a exotic derivative or option) IMHO FPGA is only part of the process. I mean, I could use it to decode market data in a fast way, replacing the ethernet card but I need a software to manage the data and coordinate not only the input but also the output when I need to send an order to a exchange for example. $\endgroup$ Feb 27, 2013 at 11:12
  • $\begingroup$ @ClebsonDerivan, with all due respect but please look up the websites of Altera and Xilinx, you will notice that they heavily target Risk Management processes which do involve optimizations. But can we kind of stay on topic if possible? Again, this was just an example where C is preferred over C++. $\endgroup$
    – Matt Wolf
    Feb 27, 2013 at 11:16
  • 2
    $\begingroup$ Freddy top500.org/lists/2012/11 all top computers are CPU/GPU based $\endgroup$ Feb 27, 2013 at 11:25
4
$\begingroup$

who told you that ? I am used to create new trade systems in C++ to make the customers requirements feasible.

CERN used C++ to prove higgs boson particle. I see people using C to program embedded like microwaves or fridges :D

but it is just my opnion, I would like to hear others.

$\endgroup$
2
  • $\begingroup$ are you referring to root.cern.ch/drupal ? amazing software +1 $\endgroup$
    – pyCthon
    Feb 27, 2013 at 2:50
  • 1
    $\begingroup$ yup and they are porting it to C++11 $\endgroup$ Feb 27, 2013 at 11:04
2
$\begingroup$

I don't know how widely used C is over C++ when it comes to doing numerical optimization; however, if there is a preference towards C it likely comes from the fact that C++ name mangling is not standard making C++ libraries very hard to integrate into other languages and environments. With C you get a well known calling convention making it straightforward to integrate which is why you see C (and Fortran) libraries that are used in Python, R, Ruby, Java, C#, etc.

$\endgroup$
3
  • 2
    $\begingroup$ I think I disagree with this assertion. C++ projects like Boost, Eigen, Armadillo, half a dozen ML libraries, ... all do very well with C++ interfaces. And if you must, you can always use a C interface for glue (as eg offered by R and used by Rcpp). $\endgroup$ Feb 27, 2013 at 2:17
  • $\begingroup$ Same here, if you are looking for a single language that is most perused to disseminate APIs, on which other libraries rely, whose interfaces are accessed/invoked, then it is surly C++. Plus do not forget that by far the still most supported of all financial APIs in aggregate is the C++ one. I think that speaks for itself. $\endgroup$
    – Matt Wolf
    Feb 27, 2013 at 2:24
  • $\begingroup$ @Matt I agree with Louis, maintaining a binary compatible application against ever changing builds of the STL and/or boost is simply impossible; MATLAB for instance brings its own libstdc++ and hence makes it impossible to link to your code that needs a more/less modern version (yes even backward compatibility is prone to break) $\endgroup$
    – hroptatyr
    Sep 6, 2013 at 6:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.