Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

code golf in C++

70 views
Skip to first unread message

Rosario19

unread,
Oct 26, 2015, 6:20:17 AM10/26/15
to
do you like my first try to the code golf problem:
http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded-cumulative-sum-of-a-vector
?
my OS tel me they are 800 bytes...
----------------------------------
#include <iostream.h>
#include <vector.h>

#define u32 unsigned
#define i32 int
#define R return
#define F for
#define SA(a) (sizeof(a)/(sizeof a[0]))
#define ooo cout
#define FF(a, b) for(a=0; a<b.size(); ++a)

template<class T> ostream& operator<<(ostream& ost, vector<T> m)
{u32 c;
FF(c, m){if(c==0) ooo<<"{";
ost<<m[c]<< (c+1!= m.size()? ", ": "}");
}
R ost;
}

void make(vector<i32>* a, vector<i32> o, i32 m, i32 b)
{u32 i;
i32 k, r=0;
FF(i,o){r+=o[i];
if(r<m) r=m;
if(r>b) r=b;
(*a)[i]=r;
}
}

int main(void)
{i32 v[]={1, 4, 6};
vector<i32> res(SA(v)), org(v,v+SA(v));
u32 c;

ooo<<"org="<<org<<"\n";
make(&res, org, 5, 10);
ooo<<"res="<<res<<"\n";
R 0;
}

seeplus

unread,
Oct 26, 2015, 6:51:44 AM10/26/15
to
On Monday, October 26, 2015 at 9:20:17 PM UTC+11, Rosario19 wrote:
> do you like my first try to the code golf problem:

/shiver/

bartekltg

unread,
Oct 26, 2015, 9:42:15 AM10/26/15
to
On 26.10.2015 11:20, Rosario19 wrote:
> do you like my first try to the code golf problem:
> http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded-cumulative-sum-of-a-vector
> ?
> my OS tel me they are 800 bytes...
> ----------------------------------
> #include <iostream.h>
> #include <vector.h>
>
> #define u32 unsigned
> #define i32 int

Are You sure that int is 32 bits;>


> #define R return
> #define F for
> #define SA(a) (sizeof(a)/(sizeof a[0]))
> #define ooo cout
> #define FF(a, b) for(a=0; a<b.size(); ++a)

Do not do that:)
You aren’t teenagers running in programming contents.
This method have some questionable advantages if you try solve
10 mathematically/algorithmically heavy but short problems in
a couple of hours and do not have time to write code, but
outside rapid solving competition is just awful style.

> #define ooo cout

WTF? ;-)


> template<class T> ostream& operator<<(ostream& ost, vector<T> m)
> {u32 c;
> FF(c, m){if(c==0) ooo<<"{";
> ost<<m[c]<< (c+1!= m.size()? ", ": "}");
> }
> R ost;
> }
>
> void make(vector<i32>* a, vector<i32> o, i32 m, i32 b)
> {u32 i;
> i32 k, r=0;
> FF(i,o){r+=o[i];
> if(r<m) r=m;
> if(r>b) r=b;
> (*a)[i]=r;
> }
> }
>
> int main(void)
> {i32 v[]={1, 4, 6};
> vector<i32> res(SA(v)), org(v,v+SA(v));
> u32 c;
>
> ooo<<"org="<<org<<"\n";
> make(&res, org, 5, 10);
> ooo<<"res="<<res<<"\n";
> R 0;
> }


You arent solving the task - starting with that you do not read the
input:/

Hmm, you want to write the shortest code possible, but you create
a long head with defines and generic vector-stream operator?
You either write a good c++ code, or code for 'shortest code'
competition. Pick one;)

best
bartekltg



Scott Lurndal

unread,
Oct 26, 2015, 12:42:40 PM10/26/15
to
bartekltg <bart...@gmail.com> writes:
>On 26.10.2015 11:20, Rosario19 wrote:
>> do you like my first try to the code golf problem:
>> http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded-cumulative-sum-of-a-vector
>> ?
>> my OS tel me they are 800 bytes...
>> ----------------------------------
>> #include <iostream.h>
>> #include <vector.h>
>>
>> #define u32 unsigned
>> #define i32 int
>
>Are You sure that int is 32 bits;>

In the vast majority of cases, yes. PDP-11 had a 16-bit
int; but there haven't been many systems using 16-bit int
since 1979.

Rosario19

unread,
Oct 26, 2015, 1:03:44 PM10/26/15
to
On Mon, 26 Oct 2015 11:20:03 +0100, Rosario19 <R...@invalid.invalid>
wrote:

>do you like my first try to the code golf problem:
>http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded-cumulative-sum-of-a-vector
>?
>my OS tel me they are 800 bytes...
>----------------------------------

always wrong this is "2.432 byte"

#include <iostream.h>
#include <stdlib.h>

#define u8 unsigned char
#define i8 signed char
#define u16 unsigned short
#define i16 signed short
#define u32 unsigned
#define i32 int
#define f64 double

#define P printf
#define R return
#define F for
#define GG(a,b) if(a)goto b
#define G goto
#define S sizeof
#define SA(a) (sizeof(a)/(sizeof a[0]))
#define ooo cout
#define FE(a,b) for(a=0; a<b.len; ++a)
#define MM malloc
#define FF free

template<class T> class V{
public:

V()
{size=0; len =0; ele=0;
va =(T*)MM(10*S(T));
if(va==0){ele=1; e=1; R;}
size=10;
}

V(u32 s)
{size=0; len =0; ele=0;
va =(T*)MM(s*S(T));
if(va==0){ele=1; e=1; R;}
size=s;
}

V(T* s, u32 sz)
{u32 i;
size=0; len =0; ele=0;
va =(T*)MM(sz*S(T));
if(va==0){ele=1; e=1; R;}
F(i=0; i<sz; ++i)
va[i]=s[i];
len =sz;
size=sz;
}

V(T& o)
{u32 i;
size=0; len =0; ele=0;
va =(T*)MM(o.len*S(T));
if(va==0){ele=1; e=1; R;}
F(i=0; i<o.len; ++i)
va[i]=o.va[i];
len =o.len;
size=o.len;
}

~V(){FF(va);}

T& operator[](u32 i)
{T *p;

if(i>=size)
{if(i>=0xFFFFFE00)
R meno1;
p=(T*) realloc(va, (i+256)*S(T));
if(p==0) R meno1;
va=p; size=i+256;
}
if(i>=len) len=i+1; // i>len assign that element
R va[i];
}

V<T>& operator=(V<T>& a)
{u32 i;
T *p;

ele=0;
if(a.ele!=0)
{
l0: ele=1; G z; /* errore trovato e riportato */
}
if(a.len>size)
{p=(T*) realloc(va, a.len*S(T));
GG(p==0, l0); va=p; size=a.len;
}
FS(i,a) va[i]=a.va[i];
len=i;
z: R *this;
}

friend ostream& operator<<(ostream& ost, V<T>& m)
{u32 c;
if(m.ele) ost<<"{vector error}";
else FE(c,m){if(c==0) ost<<"{";
ost<<m[c]<< (c+1!= m.size? ", ": "}");
}
R ost;
}

u32 size;
u32 len;
T *va;
u32 ele; // element error
static T meno1; // element error1
static u32 e; // class error
};
template<class T> u32 V<T>::e=0;
template<class T> T V<T>::meno1=(T)-1;


f(V<i32>* a, V<i32>& o, i32 m, i32 b)
{i32 k,r=0,i; FE(i,o){r+=o[i]; (*a)[i]=r=(r<m?m:(r>b?b:r));}}

int main(void)
{i32 v[]={1, 4, 6};
V<i32> res(SA(v)), org(v,SA(v));

ooo<<"org="<<org<<"\n";
f(&res, org, 5, 10);
ooo<<"res="<<res<<"\n";
R 0;
}

------------------------------

in that example i think it is bugged
there is something there
one error i don't see...

for example if i change
f(V<i32>* a, V<i32>& o, i32 m, i32 b)
in
f(V<i32>* a, V<i32> o, i32 m, i32 b)
that goes in seg fault due to double free of address
org.va (for me)

because at start of f is not called contructor for "o" parameter
but it is called the distructor at end of f()
for free the address org.va

so i think i make one error capable generate error from code the
compiler

Geoff

unread,
Oct 26, 2015, 1:47:51 PM10/26/15
to
On Mon, 26 Oct 2015 14:41:55 +0100, bartekltg <bart...@gmail.com>
wrote:

> > #define ooo cout
>
>WTF? ;-)

That should be std::cout. ;)

geoff

unread,
Oct 26, 2015, 2:05:02 PM10/26/15
to
On 2015-10-26 17:03:21 +0000, Rosario19 said:

> On Mon, 26 Oct 2015 11:20:03 +0100, Rosario19 <R...@invalid.invalid>
> wrote:

< utter garbage >

If you didn't write such absolute obfuscated shit that
you can't even parse yourself you would see the bugs in your code.

Nevertheless, here is your utter garbage, fixed.

#include <iostream>
#include <stdlib.h>

#define u8 unsigned char
#define i8 signed char
#define u16 unsigned short
#define i16 signed short
#define u32 unsigned
#define i32 int
#define f64 double

#define P printf
#define R return
#define F for
#define GG(a,b) if(a)goto b
#define G goto
#define S sizeof
#define SA(a) (sizeof(a)/(sizeof a[0]))
#define ooo std::cout
friend std::ostream& operator<<(std::ostream& ost, V<T>& m)
{u32 c;
if(m.ele) ost<<"{vector error}";
else FE(c,m){if(c==0) ost<<"{";
ost<<m[c]<< (c+1!= m.size? ", ": "}");
}
R ost;
}

u32 size;
u32 len;
T *va;
u32 ele; // element error
static T meno1; // element error1
static u32 e; // class error
};
template<class T> u32 V<T>::e=0;
template<class T> T V<T>::meno1=(T)-1;


i32 f(V<i32>* a, V<i32>& o, i32 m, i32 b)
{i32 r=0,i;FE(i,o){r+=o[i]; (*a)[i]=r=(r<m?m:(r>b?b:r));}R 0;}

int main(void)
{
i32 v[]={1, 4, 6};
V<i32> res(SA(v)), org(v,SA(v));

ooo<<"org="<<org<<"\n";
f(&res, org, 5, 10);
ooo<<"res="<<res<<"\n";
R 0;
}

Output:

org={1, 4, 6}
res={5, 9, 10}
Program ended with exit code: 0

Wouter van Ooijen

unread,
Oct 26, 2015, 2:14:03 PM10/26/15
to
Op 26-Oct-15 om 5:42 PM schreef Scott Lurndal:
8051
Mirochip PIC
Atmel AVR
MSP430
...

Wouter


Scott Lurndal

unread,
Oct 26, 2015, 2:17:10 PM10/26/15
to
Herr Ram would say "::std::cout".

Ian Collins

unread,
Oct 26, 2015, 2:23:42 PM10/26/15
to
Rosario19 wrote:
> do you like my first try to the code golf problem:
> http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded-cumulative-sum-of-a-vector
> ?
> my OS tel me they are 800 bytes...
> ----------------------------------
> #include <iostream.h>
> #include <vector.h>
>
> #define u32 unsigned
> #define i32 int
> #define R return

Idiot.


--
Ian Collins

Rosario19

unread,
Oct 26, 2015, 2:38:01 PM10/26/15
to
On Mon, 26 Oct 2015 18:03:21 +0100, Rosario19 <R...@invalid.invalid>
wrote:

>for example if i change
>f(V<i32>* a, V<i32>& o, i32 m, i32 b)
>in
>f(V<i32>* a, V<i32> o, i32 m, i32 b)
>that goes in seg fault due to double free of address
>org.va (for me)

f is traslated as

;
; f(V<i32>* a, V<i32> o, i32 m, i32 b)
;
push ebp
mov ebp,esp
add esp,-36
push ebx
push esi
push edi
mov edi,dword ptr [ebp+28]
@1:
mov eax,offset @@_$ECTVFB$@f$qp5%V$i%5%V$i%ii
call @__InitExceptBlockLDTC
mov dword ptr [ebp-8],1
;
; {i32 k,r=0,i;
;
?live16385@16: ; EDI = m
mov word ptr [ebp-20],8
xor ebx,ebx
;
; FE(i,o){r+=o[i];
;
?live16385@32: ; EBX = r, EDI = m
xor esi,esi
jmp short @3
@2:
push esi
lea eax,dword ptr [ebp+12]
push eax
call @@%V$i%@$bsubs$qui
add esp,8
add ebx,dword ptr [eax]
;
; (*a)[i]=r=(r<m?m:(r>b?b:r));
;
?live16385@48: ; EBX = r, ESI = i, EDI = m
push esi
push dword ptr [ebp+8]
call @@%V$i%@$bsubs$qui
add esp,8
cmp edi,ebx
jle short @4
mov edx,edi
jmp short @5
@4:
cmp ebx,dword ptr [ebp+32]
jle short @6
mov edx,dword ptr [ebp+32]
jmp short @7
@6:
mov edx,ebx
@7:
@5:
mov ebx,edx
mov dword ptr [eax],edx
inc esi
@3:
cmp esi,dword ptr [ebp+16]
jb short @2
;
; }
; }
;
?live16385@64: ;
dec dword ptr [ebp-8]
push dword ptr [ebp+20]
call @_free
pop ecx
mov word ptr [ebp-20],8
mov eax,dword ptr [ebp-36]
mov dword ptr fs:[0],eax
@9:
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
@@f$qp5%V$i%5%V$i%ii endp
@f$qp5%V$i%5%V$i%ii ends

as you see how smarter they are to make inline so nobody understand
what happen...
it happen that correctly the destructor is called for argument o
in f() function

but
here:
; f(&res, org, 5, 10);
;
push 10
push 5
add esp,-16
mov word ptr [ebx+16],56
mov ecx,dword ptr [ebp-32]
mov dword ptr [esp],ecx
mov eax,dword ptr [ebp-28]
mov dword ptr [esp+4],eax
mov edx,dword ptr [ebp-24]
mov dword ptr [esp+8],edx
mov ecx,dword ptr [ebp-20]
mov dword ptr [esp+12],ecx
inc dword ptr [ebx+28]
lea eax,dword ptr [ebp-16]
push eax
mov word ptr [ebx+16],44
dec dword ptr [ebx+28]
call @@f$qp5%V$i%5%V$i%ii
add esp,28

it is inline a constructor i don't know who wrote...
and what does...
[i understand that because in all constructor i have i call malloc...]


David Brown

unread,
Oct 26, 2015, 4:39:47 PM10/26/15
to
These are becoming less common, as they are pushed out by ARM Cortex-M,
but are still common. It is quite possible to program in C++ on the AVR
(an 8-bit microcontroller) and the msp430 (a 16-bit microcontroller).
There are a range of other 8-bit and 16-bit microcontrollers still in
use, but those ones are the most common - and only the AVR and msp430
are likely to be used with C++ rather than plain C.

And of course there are a few systems with 64-bit integers, and plenty
with weirder sizes like 36 that may have roots back to 1979 but are
still in use today (though perhaps not with C++).




Vir Campestris

unread,
Oct 26, 2015, 5:39:23 PM10/26/15
to
On 26/10/2015 16:42, Scott Lurndal wrote:
> In the vast majority of cases, yes. PDP-11 had a 16-bit
> int; but there haven't been many systems using 16-bit int
> since 1979.

IBM PC.
That should be enough systems for anyone.

IIRC the Windows int didn't become 32 bit until NT came out in <fx
googles> '93 and didn't become rare until the death of Windows 3.1, a
few years after '95 came out.

Andy

Paavo Helde

unread,
Oct 26, 2015, 6:00:00 PM10/26/15
to
Rosario19 <R...@invalid.invalid> wrote in
news:dcvr2b54quslppo16...@4ax.com:

> do you like my first try to the code golf problem:
> http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded
> -cumulative-sum-of-a-vector ?
> my OS tel me they are 800 bytes...

No, I don't like it. Here is a straightforward C++ solution. Most
certainly this can be improved upon e.g. by replacing min/max with ?:,
but then it would not be in full C++ spirit any more.

#include <vector>
#include <algorithm>
void c(std::vector<int>&v,int l,int h)
{int s=0;for(int& i:v)i=s=std::min(h,std::max(l,s+i));}


Below is the demo/test program:


#include <iostream>
#include <iterator> // for ostream_iterator
int main() {
int upper_lim = 6;
int lower_lim = -2;
std::vector<int> vec = {1, 4, 3, -10, 3, 2, 2, 5, -4};
c(vec, lower_lim, upper_lim);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>
(std::cout, " "));
std::cout << "\n";
// cum_vec = [1 5 6 -2 1 3 5 6 2]

upper_lim = 100;
lower_lim = -100;
vec = {1, 1, 1, 1, 1, 1};
c(vec, lower_lim, upper_lim);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>
(std::cout, " "));
std::cout << "\n";
// cum_vec = [1 2 3 4 5 6]

upper_lim = 5;
lower_lim = 0;
vec = {10, -4, -3, 2};
c(vec, lower_lim, upper_lim);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>
(std::cout, " "));
std::cout << "\n";
// cum_vec = [5 1 0 2]

upper_lim = 0;
lower_lim = 0;
vec = {3, 5, -2, 1};
c(vec, lower_lim, upper_lim);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>
(std::cout, " "));
std::cout << "\n";
//cum_vec = [0 0 0 0]

upper_lim = 10;
lower_lim = 5;
vec = {1, 4, 6};
c(vec, lower_lim, upper_lim);
std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>
(std::cout, " "));
std::cout << "\n";
// cum_vec = [5 9 10]
}

Jorgen Grahn

unread,
Oct 26, 2015, 6:59:34 PM10/26/15
to
When I bought my Commodore-Amiga in 1991, IIRC one of the two popular
C compilers there (Aztec C) had 16-bit int by default. That was with
the Motorola 68000, which had 32-bit registers, but was a little bit
better at handling 16-bit values.

Of course, a lot of programmers never had to think about the micros
until later.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

bartekltg

unread,
Oct 26, 2015, 9:47:57 PM10/26/15
to
I clearly remember 16bit int around 1995 on PC ;-)

int32_t would be better. And longer ;-)

best
bartekltg



bartekltg

unread,
Oct 26, 2015, 9:54:19 PM10/26/15
to
Yes, you are right. And Scott is even more right.
The more scope operators the better is the code...
or at least have more dots...::...

But why ::ooo::?
Obviously obfuscated output?

best
bartekltg


Geoff

unread,
Oct 27, 2015, 12:31:00 AM10/27/15
to
On Tue, 27 Oct 2015 02:54:01 +0100, bartekltg <bart...@gmail.com>
wrote:
Good one, and probably correct.

I don't know why I bothered to respond to Rosario19 at all. He seems
to think posting this kind of code is cute. Then he finds bugs,
reposts, finds more bugs, reposts and asks questions when he outsmarts
himself and can't grok his own code.

Rosario19

unread,
Oct 27, 2015, 2:56:40 AM10/27/15
to
On Mon, 26 Oct 2015 11:20:03 +0100, Rosario19 <R...@invalid.invalid>
wrote:

#include <iostream.h>
#include <stdlib.h>

#define u8 unsigned char
#define i8 signed char
#define u16 unsigned short
#define i16 signed short
#define u32 unsigned
#define i32 int
#define f64 double

#define P printf
#define R return
#define F for
#define GG(a,b) if(a)goto b
#define G goto
#define S sizeof
#define SA(a) (sizeof(a)/(sizeof a[0]))
#define ooo cout
#define FE(a,b) for(a=0; a<(b).len; ++a)
#define FC(b) for(unsigned indiceloc=0; indiceloc<(b).len;
++indiceloc)
size=0; len =0; ele=0; va=0;
i=o.ele? o.len: 10;
va =(T*)MM(i*S(T));
if(va==0){ele=1; e=1; R;}
if(i!=o.len)
{size=10;
ele =1; e=1;
FE(i,a) va[i]=a.va[i];
len=i;
z: R *this;
}

u32 assign(T* a, u32 c)
{u32 j;
T *p;
if(c>=size)
{if(c>=0xFFFFFE00)
R -1;
p=(T*) realloc(va, c*S(T));
if(p==0) R -1;
va=p; size=c;
}
F(j=0; j<c; ++j) va[j]=a[j];
len=c;
R 0;
}

friend ostream& operator<<(ostream& ost, V<T>& m)
{u32 c;
if(m.ele) ost<<"{vector error}";
else FE(c,m){if(c==0) ost<<"{";
ost<<m[c]<< (c+1!= m.len? ", ": "}");
}
R ost;
}

u32 size;
u32 len;
T *va;
u32 ele; // element error
static T meno1; // element error1
static u32 e; // class error
};
template<class T> u32 V<T>::e=0;
template<class T> T V<T>::meno1=(T)-1;

//81
f(V<i32>*a,i32 m,i32 b){i32
r=0,*p=a->va;FC(*a){r+=*p;*p++=r=(r<m?m:(r>b?b:r));}}

int main(void)
{i32 v1[]={1, 4, 3, -10, 3, 2, 2, 5, -4},
v2[]={1, 1, 1, 1, 1, 1},
v3[]={10, -4, -3, 2},
v4[]={3, 5, -2, 1},
v5[]={1, 4, 6};
i32 upper_lim;
i32 lower_lim;
V<i32> org;

upper_lim = 6;
lower_lim = -2;
org.assign(v1, SA(v1));
ooo<<"input ="<<org<<"\n";
f(&org, lower_lim, upper_lim);
ooo<<"output="<<org<<"\n";
ooo<<"result=[1 5 6 -2 1 3 5 6 2]\n";


upper_lim = 100;
lower_lim = -100;
org.assign(v2, SA(v2));
ooo<<"input ="<<org<<"\n";
f(&org, lower_lim, upper_lim);
ooo<<"output="<<org<<"\n";
ooo<<"result=[1 2 3 4 5 6]\n";

upper_lim = 5;
lower_lim = 0;
org.assign(v3, SA(v3));
ooo<<"input ="<<org<<"\n";
f(&org, lower_lim, upper_lim);
ooo<<"output="<<org<<"\n";
ooo<<"result=[5 1 0 2]\n";

upper_lim = 0;
lower_lim = 0;
org.assign(v4, SA(v4));
ooo<<"input ="<<org<<"\n";
f(&org, lower_lim, upper_lim);
ooo<<"output="<<org<<"\n";
ooo<<"result=[0 0 0 0]\n";

upper_lim = 10;
lower_lim = 5;
org.assign(v5, SA(v5));
ooo<<"input ="<<org<<"\n";
f(&org, lower_lim, upper_lim);
ooo<<"output="<<org<<"\n";
ooo<<"result=[5 9 10]\n";

R 0;
}
---------

input ={1, 4, 3, -10, 3, 2, 2, 5, -4}
output={1, 5, 6, -2, 1, 3, 5, 6, 2}
result=[1 5 6 -2 1 3 5 6 2]
input ={1, 1, 1, 1, 1, 1}
output={1, 2, 3, 4, 5, 6}
result=[1 2 3 4 5 6]
input ={10, -4, -3, 2}
output={5, 1, 0, 2}
result=[5 1 0 2]
input ={3, 5, -2, 1}
output={0, 0, 0, 0}
result=[0 0 0 0]
input ={1, 4, 6}
output={5, 9, 10}
result=[5 9 10]


Christian Gollwitzer

unread,
Oct 27, 2015, 3:30:40 AM10/27/15
to
Am 27.10.15 um 07:56 schrieb Rosario19:
> On Mon, 26 Oct 2015 11:20:03 +0100, Rosario19 <R...@invalid.invalid>
> wrote:
>
>> do you like my first try to the code golf problem:
>> http://codegolf.stackexchange.com/questions/61684/calculate-the-bounded-cumulative-sum-of-a-vector
>> ?
>
> #include <iostream.h>
> #include <stdlib.h>
> [....]

Ah, you invented a new discipline: Anti-golf. That's why you use .h
include files

Christian

David Brown

unread,
Oct 27, 2015, 4:49:55 AM10/27/15
to
On 26/10/15 23:59, Jorgen Grahn wrote:
> On Mon, 2015-10-26, Vir Campestris wrote:
>> On 26/10/2015 16:42, Scott Lurndal wrote:
>>> In the vast majority of cases, yes. PDP-11 had a 16-bit
>>> int; but there haven't been many systems using 16-bit int
>>> since 1979.
>>
>> IBM PC.
>> That should be enough systems for anyone.
>>
>> IIRC the Windows int didn't become 32 bit until NT came out in
>> <fx googles> '93 and didn't become rare until the death of Windows 3.1,
>> a few years after '95 came out.
>
> When I bought my Commodore-Amiga in 1991, IIRC one of the two popular
> C compilers there (Aztec C) had 16-bit int by default. That was with
> the Motorola 68000, which had 32-bit registers, but was a little bit
> better at handling 16-bit values.

The original 68k was almost twice as fast at handling 16-bit values,
since it had a 16-bit ALU and internal datapath. The design was for
16-bit cpu, since that was the standard at the time and a "real" 32-bit
implementation would have been far too costly, but with a clear and
fully-supported 32-bit path towards future versions. It was one of the
very few designs which was made flexible for forward compatibility,
rather than (like the x86 line) crippled by backward compatibility.

David Brown

unread,
Oct 27, 2015, 4:52:47 AM10/27/15
to
That's how Rosario19 writes his code - at least in newsgroups
(presumably he does not write code like that for a living). He is
usually to be found in comp.lang.c, rather than here, and he writes this
kind of line noise regularly. I have no idea why. People in c.l.c.
usually just ignore him.


asetof...@gmail.com

unread,
Oct 27, 2015, 5:51:20 AM10/27/15
to
Ah, you invented a new discipline: Anti-golf. That's why you use .h
include files

Christian
_______
My target is not win that
competition with C++
it is write a C++ library + macro def
that allow C++ compete with
their languages Apl in the middle

Scott Lurndal

unread,
Oct 27, 2015, 8:59:09 AM10/27/15
to
I've seen systems with 64-bit "long int", but I've not seen
systems with 64-bit "int" - do you have any references?

The only oddball systems left in production are 48-bit (Unisys Clearpath Libra/Burroughs)
and 36-bit (Unisys Clearpath Dorado/Univac), and they're both emulated nowadays.

I believe the libra (formerly burroughs large systems) systems have a C
compiler, but I'm not sure about C++.

David Brown

unread,
Oct 27, 2015, 10:02:23 AM10/27/15
to
On 27/10/15 13:58, Scott Lurndal wrote:
> David Brown <david...@hesbynett.no> writes:
>> On 26/10/15 19:13, Wouter van Ooijen wrote:
>
>> And of course there are a few systems with 64-bit integers, and plenty
>> with weirder sizes like 36 that may have roots back to 1979 but are
>> still in use today (though perhaps not with C++).
>>
>
> I've seen systems with 64-bit "long int", but I've not seen
> systems with 64-bit "int" - do you have any references?

I think Crays used 64-bit int, and there were some Sparc64 systems with
64-bit int. I don't know of any that would be considered common or
mainstream - I merely point out that such systems exist.

64-bit long is, of course, extremely common - it is standard in 64-bit
*nix systems. Windows is unusual in having 32-bit longs in their 64-bit OS.

>
> The only oddball systems left in production are 48-bit (Unisys Clearpath Libra/Burroughs)
> and 36-bit (Unisys Clearpath Dorado/Univac), and they're both emulated nowadays.

I wasn't thinking of new systems in production, but old oddball systems
that are still running - some of these old mainframes never seem to die.

Of course, there are very, very few, if any, systems around where it is
likely that one would be writing new code in C++ (or even C) that has an
int size other than 32-bit or 16-bit.
0 new messages