Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.physics > #626546
| From | Jeff-Relf.Me @. |
|---|---|
| Newsgroups | comp.os.linux.advocacy, sci.physics, comp.lang.c++ |
| Subject | No _serious programming language lacks "evil" macros ! ! |
| Date | 2017-04-03 00:42 -0700 |
| Organization | MB-NET.NET for Open-News-Network e.V. |
| Message-ID | <Jeff-Relf.Me@Apr.3--0.42A.Seattle.2017> (permalink) |
| References | (1 earlier) <obii4i$m36$1@dont-email.me> <njtpdc5354qqii10m80t3htjglscka44rs@4ax.com> <obj166$7rj$3@dont-email.me> <Jeff-Relf.Me@Mar.30--1.07P.Seattle.2017> <obsp3m$11mu$1@adenine.netfront.net> |
Cross-posted to 3 groups.
> > 2 weeks ago, you ( DFS ) showed me
> > your "readable and maintainable" code:
> >
> > int isleapyear(int yr) {
> > if(((yr%4==0) && (yr%100!=0)) || (yr%400==0))
> > {return 0;}
> > return -1;
> > } // oackac$fve$1@dont-email.me
> >
> > Then I showed you my "kooky and oddly formatted" version of it:
> >
> > #define isLeapYear(y) ( !( y%400 ) || y%100 && !( y%4 ) )
>
> Who are you talking to?
Mr. DFS, see above; the thread ( oldest first ):
JeffRelf Jeff-Relf.Me@Mar.30--1.54A.Seattle.2017
PeterKöhlmann obii4i$m36$1@dont-email.me
MrChrisV njtpdc5354qqii10m80t3htjglscka44rs@4ax.com
MrDFS obj166$7rj$3@dont-email.me
JeffRelf Jeff-Relf.Me@Mar.30--1.07P.Seattle.2017
Juha_Nieminen obsp3m$11mu$1@adenine.netfront.net
> Consider what happens if you call it eg. like isLeapYear(a+b).
> Even when you fix the macro, there's still the problem of calling it
> like isLeapYear(someReallyExpensiveFunctionThatTakesAMinuteToReturn()).
Thanks for dreaming up scary scenarios however,
like guns and knives, macros are useful too, not just dangerous.
No _serious programming language lacks "evil" macros.
Here's some more "scary" macros for you...
MicroSoft's WinMerge uses this this algorithm:
" Dynamic Programming | Set 4 (Longest Common Subsequence) "
http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence/
My code, below, produces the same results as WinMerge:
// ScreenShot: http://Jeff-Relf.Me/Diff.PNG
// Help/Settings: http://Jeff-Relf.Me/X.HTM
// _FileCmp(), below, records thousands of matching lines ( text ),
// LeftOlder vs RightNewer, using the "LongestCommonSequence"
// ( shortest diffs ) algorithm.
//
// BB is a pointer to the start of
// a dynamic array of ( contiguous ) pointers ( lines );
// PP points to the end of the array.
//
// BB and PP are from the LeftOlder file.
// _BB and _PP are from the RightNewer file.
_FileCmp( LnA BB, LnA _BB, LnA PP, LnA _PP, LnT &Ln ) {
int Rows = PP - BB + 1, Cols = _PP - _BB + 1 ; u64 Row = Rows, Col = Cols ;
// Allocate a " LeftOlderLines * RightNewerLines " table of 32 bit integers
// to store all LongestCommonSequence Lengths.
pInt _Table = (pInt)MallocTmp( Rows * Cols * szInt );
{ LoopRow( Rows ) { LoopCol( Cols ) {
if ( !Row || !Col ) { Table( Row, Col ) = 0 ; continue ; }
if ( aMatch ) Table( Row, Col ) = Table( Row - 1, Col - 1 ) + 1 ;
else Table( Row, Col ) = ER( Table( Row, Col - 1 ), Table( Row - 1, Col ) ); } } }
// " Ln " is a dynamic array of thousands of ( contiguous ) 64 bit pointers,
// repurosed to store two 32 bit intergers ( Row and Col ) in a pointer.
// If both files are the same, with X Lines, it'll store X RowCol pairs.
//
// The first " StoreRowColumn ", below, stores the end of the files;
// the last is first, and vice versa; it's reversed.
Zero( Ln ), StoreRowColumn;
while ( Row > 0 && Col > 0 )
if ( aMatch ) StoreRowColumn ;
else Table( Row, Col - 1 ) > Table( Row - 1, Col ) ? Col-- : Row-- ; }
Near Globals:
// Access " _Table ", a One Dimensional array, as if it were Two Dimensional.
#define Table( i, j ) _Table[ ( j ) * Rows + i ]
// F[-1] is the ( 16 bit ) length of the leading whitespace.
#define aMatch ( F = BB[ Row - 1 ], _F = _BB[ Col - 1 ], F[-1] == _F[-1] && Eq( F, _F ) )
// Store the matching lines as line numbers from LeftOlder and RightNewer
#define StoreRowColumn ( Inc( Ln ) = LnP( Row - 1 << 32 | Col - 1 ), Row--, Col-- )
LnP F, _F ;
Far Globals:
#define Zero( X ) memset( & X, 0, sizeof X )
#define Eq !strCmp
#define LoopRows( N ) int Row = -1, eRow = ( N ) - 1 ; while ( ++Row <= eRow )
#define LoopCols( N ) int Col = -1, eCol = ( N ) - 1 ; while ( ++Col <= eCol )
typedef wchar_t wchar ; typedef wchar *LnP ; typedef LnP *LnA ;
typedef int *pInt ; typedef void *Void_P ; typedef unsigned __int64 u64 ;
const int szInt = sizeof( int );
struct LnT { LnA BB, PP, maxPP ; }; LnT Ln ;
// " Inc() ", below, dynamically allocates thousands of ( contiguous ) pointers.
// When diff is done, " Temp_Heap " is simply destroyed.
template < typename TyT, typename TyA, typename TyP >
TyP & Inc( TyT & Xx, int N ) { int I_PP, I_PP_New, I_maxPP, rv, Sz, Temp_Heap = N >= 0 ; if ( !Temp_Heap ) N = 1 ;
I_PP = !Xx.PP ? -1 : Xx.PP - Xx.BB, I_maxPP = !Xx.maxPP ? 0 : Xx.maxPP - Xx.BB, I_PP_New = I_PP + N ; if( I_maxPP < 0 ) exit(1);
if ( I_PP_New < I_maxPP ) { OK: return Xx.PP = Xx.BB + I_PP_New, *Xx.PP ; }
rv = ER( 1024, 3 * I_PP_New ), Sz = 16 + rv * szPtr ;
Xx.maxPP = Xx.BB = TyA( Temp_Heap ? ReAllocTmp( Xx.BB, ++I_PP * szPtr, Sz ) : realloc( Xx.BB, Sz ) ), Xx.maxPP += rv ;
if( !Xx.BB ) exit(1); goto OK ; }
LnP &Inc( LnT &Ln ) { return Inc< LnT, LnA, LnP>( Ln, 1 ) ; }
LnP ReAllocTmp( Void_P B⁰, int Sz⁰, int Sz ) { Void_P B = B⁰ ; if ( Sz > 0 && Sz > Sz⁰ ) B = MallocTmp( Sz );
if ( B⁰ && Sz⁰ > 0 ) memmove( B, B⁰, Sz⁰ ); return LnP( B ); }
Back to sci.physics | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I found a CostFree INN ( Usenet ) server that allows HTML. Jeff-Relf.Me @. - 2017-03-30 01:54 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-03-30 11:14 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-03-30 07:38 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. chrisv <chrisv@nospam.invalid> - 2017-03-30 07:17 -0500
No _serious programming language lacks "evil" macros ! ! Jeff-Relf.Me @. - 2017-03-30 13:07 -0700
21 lines, 74 columns, no macros. Jeff-Relf.Me @. - 2017-03-30 20:21 -0700
Re: No _serious programming language lacks "evil" macros ! ! Juha Nieminen <nospam@thanks.invalid> - 2017-04-03 06:12 +0000
No _serious programming language lacks "evil" macros ! ! Jeff-Relf.Me @. - 2017-04-03 00:42 -0700
Re: No _serious programming language lacks "evil" macros ! ! Juha Nieminen <nospam@thanks.invalid> - 2017-04-04 06:08 +0000
Re: No _serious programming language lacks "evil" macros ! ! Jerry Stuckle <jstucklex@attglobal.net> - 2017-04-04 09:06 -0400
Re: No _serious programming language lacks "evil" macros ! ! Jerry Stuckle <jstucklex@attglobal.net> - 2017-04-04 09:08 -0400
You know it's inlined when you can't set a break point on it. Jeff-Relf.Me @. - 2017-04-04 10:47 -0700
Re: You know it's inlined when you can't set a break point on it. Jerry Stuckle <jstucklex@attglobal.net> - 2017-04-04 14:08 -0400
Re: No _serious programming language lacks "evil" macros ! ! chrisv <chrisv@nospam.invalid> - 2017-04-04 07:23 -0500
Re: No _serious programming language lacks "evil" macros ! ! Silver-Tongued Heel <sl@im.er> - 2017-04-04 12:43 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. "jasper@shared-secrets.com" <jasper@shared-secrets.com> - 2017-04-10 00:58 +0000
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 08:36 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. chrisv <chrisv@nospam.invalid> - 2017-04-10 06:51 -0500
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 08:12 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 14:22 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 12:10 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 19:48 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. snipeco.2@gmail.com (Sn!pe) - 2017-04-10 19:12 +0100
Re: I found a CostFree INN ( Usenet ) server that allows HTML. chrisv <chrisv@nospam.invalid> - 2017-04-10 13:38 -0500
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 15:14 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Chris Ahlstrom <OFeem1987@teleworm.us> - 2017-04-10 18:52 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 19:22 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 15:13 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Snit <usenet@gallopinginsanity.com> - 2017-04-10 13:04 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2017-04-10 22:07 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. chrisv <chrisv@nospam.invalid> - 2017-04-10 07:48 -0500
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 12:11 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Nomen Nescio <nobody@dizum.com> - 2017-04-11 07:33 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Snit <usenet@gallopinginsanity.com> - 2017-04-10 09:48 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 19:46 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Snit <usenet@gallopinginsanity.com> - 2017-04-10 11:05 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Cornelis Tromp <nobody@holland.remailer.nl> - 2017-04-11 06:41 +0100
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 08:12 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 14:22 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 12:13 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 19:44 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Snit <usenet@gallopinginsanity.com> - 2017-04-10 11:13 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Silver-Tongued Heel <sl@im.er> - 2017-04-10 15:17 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Snit <usenet@gallopinginsanity.com> - 2017-04-10 12:36 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-04-10 23:29 +0200
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Snit <usenet@gallopinginsanity.com> - 2017-04-10 14:41 -0700
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Chris Ahlstrom <OFeem1987@teleworm.us> - 2017-04-10 18:48 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Anonymous <anonymous@foto.nl1.torservers.net> - 2017-04-10 07:08 -0400
Re: I found a CostFree INN ( Usenet ) server that allows HTML. Fritz Wuehler <fritz@spamexpire-201704.rodent.frell.theremailer.net> - 2017-04-10 13:53 +0000
csiph-web