Re: program that compiles in C but not in C++?

From: Nils O. Selåsdal (noselasd_at_frisurf.no)
Date: 01/10/04


Date: Sat, 10 Jan 2004 17:37:11 +0100

In article <btn8v2$olk$1@daisy.noc.ucla.edu>, Digital Puer wrote:
> I came across a question that asked for me to write a
> small program that will compile in C but not in C++.
> Any ideas?
>
> The only one I can think of is one that tries to
> downcast a void * to a more specific pointer without
> a cast:
void foo(){
        unsigned char c = 0xfa;
        char *d = &c;
}

void foo(){
        char or[] = "or";
}

-- 
Nils Olav Selåsdal <NOS@Utel.no>
System Developer, UtelSystems a/s
w w w . u t e l s y s t e m s . c o m


Relevant Pages

  • Re: pass by Reference/value ???
    ... > void foo ... this would be called "passing by reference". ... foo receives a local copy of s and any changes that it makes to s only ... Since s is a pointer, a variable storing the address of s is a pointer to ...
    (comp.lang.cpp)
  • Re: Building extensibility into an API
    ... otherwise of "building extensibility into an API". ... Now maybe you think of some cool improvement to foo that you could make, ... foo_v2(int bar, char *baz, long double newparam); ... Each function you write takes an unused void * parameter. ...
    (comp.lang.c)
  • Re: Library bug or my fault?
    ... compiled using ARM/Linux cross-compiler and run on an ARM9 target. ... void memcpy ... 29 void cp(const Foo *foo) ... 31 Bar bar; ...
    (comp.lang.c)
  • Re: Void function returns value
    ... "The value of a void expression (an expression that has ... void foo() ... I knew the compiler needs a function pointer, ...
    (comp.std.c)
  • Re: [C] return statement in void function?
    ... struct foo copy{ ... compiler really does have to think about. ... T foo (U fxn) ... > evaluates to void. ...
    (alt.comp.lang.learn.c-cpp)