Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Is this a Standard Portable C Program?

Reply
Thread Tools

Is this a Standard Portable C Program?

 
 
Citizen C
Guest
Posts: n/a
 
      01-06-2009
#include <stdio.h>
#define p printf
#define r0 return 0;
#define P int main(void)\
{\
p("Hello world! NULL is %p\n", (void*)NULL);\
r0\
}
P

/*
I think it is because Microsoft and gcc say so!

Cheers!
--
Citizen C
*/
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      01-06-2009
Citizen C wrote:
> #include <stdio.h>
> #define p printf
> #define r0 return 0;
> #define P int main(void)\
> {\
> p("Hello world! NULL is %p\n", (void*)NULL);\
> r0\
> }
> P


Once you get rid of the stupid preprocessor tricks, this expands (apart
from any expansion of <stdio.h> to

#include <stdio.h>
int main(void){ printf("Hello world! NULL is %p\n", (void*)NULL); return 0;}

or, in a sane world,

#include <stdio.h>
int main(void)
{
printf("Hello world! NULL is %p\n", (void *) NULL);
return 0;
}


Now, tell me, do _you_ think this is a standard portable program?
Stupid preprocessor tricks are for infants.
 
Reply With Quote
 
 
 
 
vippstar@gmail.com
Guest
Posts: n/a
 
      01-06-2009
On Jan 6, 6:36 am, Citizen C <alex566...@aol.com> wrote:
> #include <stdio.h>
> #define p printf
> #define r0 return 0;
> #define P int main(void)\
> {\
> p("Hello world! NULL is %p\n", (void*)NULL);\
> r0\
> }
>
> P


Yes
 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      01-06-2009
On 6 Jan, 04:36, Citizen C <alex566...@aol.com> wrote:
> #include <stdio.h>
> #define p printf
> #define r0 return 0;
> #define P int main(void)\
> {\
> * *p("Hello world! NULL is %p\n", (void*)NULL);\
> * *r0\}
>
> P
>
> /*
> I think it is because Microsoft and gcc say so!


Why did you suspect it wasn't? That is why did you needd to "test"
it with MS and gcc?

Note 1: using a couple of compilers does *not* prove a program
standard and portable.

Note 2: the style is really crap (it would fail reveiew in any
reasonable development environment)


--
Nick Keighley
 
Reply With Quote
 
saul.plonkerton@gmail.com
Guest
Posts: n/a
 
      01-06-2009
#include <stdio.h>
#define HAN int main (void)
#define HAS { printf(
#define A "Hello world! "
#define WART "I'm a piece of ****!\n");
#define ON return
#define HIS 0;
#define DICK }

HAN HAS A WART ON HIS DICK
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      01-06-2009
writes:

> On 6 Jan, 04:36, Citizen C <alex566...@aol.com> wrote:
>> #include <stdio.h>
>> #define p printf
>> #define r0 return 0;
>> #define P int main(void)\
>> {\
>> Â* Â*p("Hello world! NULL is %p\n", (void*)NULL);\
>> Â* Â*r0\}
>>
>> P
>>
>> /*
>> I think it is because Microsoft and gcc say so!

>
> Why did you suspect it wasn't? That is why did you needd to "test"
> it with MS and gcc?


Err, they are the compilers he uses?

>
> Note 1: using a couple of compilers does *not* prove a program
> standard and portable.


Actually it does prove its portable - between the machines of interest
for those compiler versions he mentions.

>
> Note 2: the style is really crap (it would fail reveiew in any
> reasonable development environment)
>
>
> --
> Nick Keighley


--
I'm not a person who particularly had heros when growing up.
- Dennis Ritchie when asked about the hero worship coming from c.l.c
 
Reply With Quote
 
saul.plonkerton@gmail.com
Guest
Posts: n/a
 
      01-06-2009
On Jan 6, 5:49*am, Han from China - Master Troll <autistic-
lamer...@comp.lang.c> wrote:
> > HAN HAS A WART ON HIS DICK

>
> I thought it was a nice way to add some girth.


thats kind of hack and technically invokes UB, phalloplasty is at
least standard-comformant.

> "Only entropy comes easy." -- Anton Chekhov


if i ever have a daughter, im going name her "entropy" just so i can
say that same thing about her.

----- ---- - - - ---- - -+
SIGNATURE
 
Reply With Quote
 
vippstar@gmail.com
Guest
Posts: n/a
 
      01-06-2009
On Jan 6, 12:58*pm, Richard <rgrd...@gmail.com> wrote:
> nick_keighley_nos...@hotmail.com writes:
> > Note 1: using a couple of compilers does *not* prove a program
> > standard and portable.

>
> Actually it does prove its portable - between the machines of interest
> for those compiler versions he mentions.


You're wrong. UB is UB. It may compile once without any errors and
never compile again with a lot of errors. Compiling proves nothing.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      01-06-2009
wrote:
> On Jan 6, 12:58 pm, Richard <rgrd...@gmail.com> wrote:
>> nick_keighley_nos...@hotmail.com writes:
>>> Note 1: using a couple of compilers does *not* prove a program
>>> standard and portable.

>> Actually it does prove its portable - between the machines of interest
>> for those compiler versions he mentions.

>
> You're wrong. UB is UB. It may compile once without any errors and
> never compile again with a lot of errors. Compiling proves nothing.


True; only by studying the documentation for the implementations in
question can you discover whether they provide a definition of the
behavior that the standard leaves undefined. If both implementations
provide definitions compatible with your code, then it is portable
between those two implementations, at least. However, if either
implementation's documentation is silent on a relevant issue, all bets
are off.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      01-06-2009
Citizen C wrote:
> #include <stdio.h>
> #define p printf
> #define r0 return 0;
> #define P int main(void)\
> {\
> p("Hello world! NULL is %p\n", (void*)NULL);\
> r0\
> }
> P
>
> /*
> I think it is because Microsoft and gcc say so!
>
> Cheers!


A diagnostic is required because the posted code violates
the constraint of 5.1.1.1p3: "[...] A source file shall not end
in a partial preprocessing token or in a partial comment. [...]"
Other than that, I see nothing incorrect about it -- silly, yes,
but not actually incorrect.

--
Eric Sosman
lid
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Portable/standard way of counting number of bits in variable? Dale Dellutri C Programming 9 04-04-2009 03:40 PM
is this portable, conforming to standard, elegant? r.z. C++ 32 02-17-2007 08:57 AM
Portable Python - free portable development environment ! perica.zivkovic@gmail.com Python 7 01-13-2007 11:19 AM
portable (VHDL) vs. non-portable (altera LPM) approaches to signed computations Eli Bendersky VHDL 1 03-01-2006 02:43 PM
Directory/File recursive listing using standard/portable C? ibic C Programming 10 11-22-2004 06:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57