Everything2
Near Matches
Ignore Exact
Full Text
Everything2

C program that is not a C++ program

created by ariels

(idea) by ariels (5.5 d) (print)   ?   (I like it!) 1 C! Mon Sep 25 2000 at 20:54:45

#include <stdlib.h>
#include <stdio.h>

int main()
{
  int *new = malloc(10*sizeof(*new));

  printf("The address of new is %p\n", (void*)new);

  return EXIT_SUCCESS;
}

Please compile this on your C compiler, with the maximal level of warnings (gcc -pedantic -Wall might be a good place to start). This program is strictly conforming standard ISO C.

Now please try to compile it with your C++ compiler, with the maximal level of warnings (g++ -pedantic -Wall is a nice try, although it will accept both includes, which strictly speaking are deprecated in ISO standard C++, either). I count 3 corrections required to make it into a horrible but conforming C++ program.

C != C++

(no, that's not legal C OR C++...)

The noder known as ISO C. Gorgonzola points out it is legal C and legal C++. Just that its value is undefined by both ISO C and ISO C++.


(idea) by stupot (6.3 mon) (print)   ?   (I like it!) Fri Jan 18 2002 at 23:06:06

The following program will print a different value for a depending on whether it is compiled in C (pre C99 standard) or C++

#include <stdio.h>
void main()
{
   int a;
   a=4//**/2;
   ;
   printf("%d\n",a);
}

The reason being that traditional C reads the line as a=4/2; with a comment in the middle. C++ (and C99) comments out the whole line after the 4, and uses the following semicolon to end the line.


printable version
chaos

C++: (a=b)=c Why are homosexuals held to different standards of conduct than heterosexuals? Gay Standard Time (GST) standard male disclaimer
C/C++ Casting the return value of malloc() The Design and Evolution of C++ Effective C++
The quickest way to crash Windows NT/2000/XP C99 Clean white walls stdio.h
cout Huh? #include size_t
Walls of Jericho GCC gorgonzola Brother and Sister
keyword C == C++ whimsy silent but deadly
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Nodes to live by:
Please stop thanking me for cooling your writeup
White Star Line
Adam Purcell
Sticky toffee pudding
Why I gave up on anarchy
My brother made $700 in 3 hours by sitting in front of a grocery store
Dance of Death
Food in the Middle Ages
AA
Speed chess, confessions of a positional player
Wannsee Conference
ad maiora natus sum
In praise of older women
New Writeups
Lord Brawl
Dr. Horrible's Sing-Along Blog(review)
a8ksh4
regret(idea)
Heisenberg
Editor Log: July 2008(log)
sam512
halfway homes, catacombs, twilight zones(fiction)
Timeshredder
The Texas UFO Crash of 1897(event)
Heitah
The Dark Knight(review)
ignis_glaciesque
Uppsala(place)
ignis_glaciesque
diffusion of responsibility(idea)
TheOrientalAfrican
The Soft Meadow of my Childhood(event)
BookReader
The Dragon Slayers(fiction)
kohlcass
religiously fashionable(review)
Pavlovna
waulking song(thing)
tentative
Stick Man(poetry)
Ereneta
The Fight with the Snapping Turtle: Or, the American St. George(poetry)
sitaraika
Fog and fire(personal)
E2 is a by-product of the existence of The Everything Development Company