public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -fdefault-integer-8 in c
@ 2010-03-09 22:41 José Luis García Pallero
  2010-03-10  0:15 ` Nicholas Sherlock
  2010-03-10 11:56 ` John (Eljay) Love-Jensen
  0 siblings, 2 replies; 8+ messages in thread
From: José Luis García Pallero @ 2010-03-09 22:41 UTC (permalink / raw)
  To: gcc-help

Hello,
Is possible to force integers to be 8 bytes length in gcc as in
gfortran? I need to do some maths and I need a matrix larger than 2GB
but my functiosns are programmed with indexes as int.

Thanks

-- 
*****************************************
José Luis García Pallero
jgpallero@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -fdefault-integer-8 in c
  2010-03-09 22:41 -fdefault-integer-8 in c José Luis García Pallero
@ 2010-03-10  0:15 ` Nicholas Sherlock
  2010-03-10 11:56 ` John (Eljay) Love-Jensen
  1 sibling, 0 replies; 8+ messages in thread
From: Nicholas Sherlock @ 2010-03-10  0:15 UTC (permalink / raw)
  To: gcc-help

On 10/03/2010 11:41 a.m., José Luis García Pallero wrote:
> Hello,
> Is possible to force integers to be 8 bytes length in gcc as in
> gfortran? I need to do some maths and I need a matrix larger than 2GB
> but my functiosns are programmed with indexes as int.

#define int long

?

<shudders> :)

I think the best way to do that would be to replace int with some type 
like "matrix_index", that way you can either:

typedef int matrix_index;

or

typedef long matrix_index;

Depending on how much precision you want at the time.

Cheers,
Nicholas Sherlock

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: -fdefault-integer-8 in c
  2010-03-09 22:41 -fdefault-integer-8 in c José Luis García Pallero
  2010-03-10  0:15 ` Nicholas Sherlock
@ 2010-03-10 11:56 ` John (Eljay) Love-Jensen
  2010-03-10 12:36   ` José Luis García Pallero
  1 sibling, 1 reply; 8+ messages in thread
From: John (Eljay) Love-Jensen @ 2010-03-10 11:56 UTC (permalink / raw)
  To: José Luis García Pallero, gcc-help

Hi José,

Is there any reason you can't use int64_t from <stdint.h>?

Or use int64_t indirectly by:

#include <stdint.h>
typedef int64_t matrix_index;

The difficulty then will be to scrub your code to replace your int index types with matrix_index index type.

On a 64-bit machine, where the natural word size is 64, I think that int should be 64-bit.  But apparently my preferences are not in vogue.

On all the 64-bit machines I use, int is half-word size (32-bit).

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -fdefault-integer-8 in c
  2010-03-10 11:56 ` John (Eljay) Love-Jensen
@ 2010-03-10 12:36   ` José Luis García Pallero
  2010-03-10 13:16     ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 8+ messages in thread
From: José Luis García Pallero @ 2010-03-10 12:36 UTC (permalink / raw)
  To: John (Eljay) Love-Jensen; +Cc: gcc-help

El día 10 de marzo de 2010 12:55, John (Eljay) Love-Jensen
<eljay@adobe.com> escribió:
> Hi José,
>
> Is there any reason you can't use int64_t from <stdint.h>?
>
> Or use int64_t indirectly by:
>
> #include <stdint.h>
> typedef int64_t matrix_index;
>
> The difficulty then will be to scrub your code to replace your int index types with matrix_index index type.
>
> On a 64-bit machine, where the natural word size is 64, I think that int should be 64-bit.  But apparently my preferences are not in vogue.
>
> On all the 64-bit machines I use, int is half-word size (32-bit).
>
> Sincerely,
> --Eljay
>

Yes, if I use typedef I would to replace the definition in all my code
and it would be dangerous. But the problem is third party software,
for example BLAS (CBLAS interface). Users of fortran haven't the
problem because they can use at BLAS/LAPACK compile time the flag
-fdefault-integer-8, but C/C++ users can't do it.

-- 
*****************************************
José Luis García Pallero
jgpallero@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: -fdefault-integer-8 in c
  2010-03-10 12:36   ` José Luis García Pallero
@ 2010-03-10 13:16     ` John (Eljay) Love-Jensen
  2010-03-10 14:43       ` José Luis García Pallero
  0 siblings, 1 reply; 8+ messages in thread
From: John (Eljay) Love-Jensen @ 2010-03-10 13:16 UTC (permalink / raw)
  To: José Luis García Pallero; +Cc: gcc-help

Hi José,

> Yes, if I use typedef I would to replace the definition in all my code and it would be dangerous.

<stdint.h>'s int64_t is int64_t on all platforms which have a 64-bit integer type, for C.

I'm not seeing the dangerousness.  Unless you mean C++, which does not have int64_t (except by the C++ compilers which have added it as an extension, or added it in anticipation of C++0x).

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -fdefault-integer-8 in c
  2010-03-10 13:16     ` John (Eljay) Love-Jensen
@ 2010-03-10 14:43       ` José Luis García Pallero
  2010-03-10 14:54         ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 8+ messages in thread
From: José Luis García Pallero @ 2010-03-10 14:43 UTC (permalink / raw)
  To: John (Eljay) Love-Jensen; +Cc: gcc-help

El día 10 de marzo de 2010 14:13, John (Eljay) Love-Jensen
<eljay@adobe.com> escribió:
> Hi José,
>
>> Yes, if I use typedef I would to replace the definition in all my code and it would be dangerous.
>
> <stdint.h>'s int64_t is int64_t on all platforms which have a 64-bit integer type, for C.
>
> I'm not seeing the dangerousness.  Unless you mean C++, which does not have int64_t (except by the C++ compilers which have added it as an extension, or added it in anticipation of C++0x).

Would be possible to use something like #define int long in the code.


-- 
*****************************************
José Luis García Pallero
jgpallero@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: -fdefault-integer-8 in c
  2010-03-10 14:43       ` José Luis García Pallero
@ 2010-03-10 14:54         ` John (Eljay) Love-Jensen
  2010-03-10 18:35           ` José Luis García Pallero
  0 siblings, 1 reply; 8+ messages in thread
From: John (Eljay) Love-Jensen @ 2010-03-10 14:54 UTC (permalink / raw)
  To: José Luis García Pallero; +Cc: gcc-help

Hi José,

> Would be possible to use something like #define int long in the code.

That would be possible.  (Along the same lines as "It would be possible to kill a fly using a 12 PW orbital satellite laser.")

I strongly discourage such a solution.

From a C (or C++) point of view, such a solution would be "very bad".  I would rank it in the top ten worst coding practices for C/C++, were such to be used.

I am rather biased against programming in the Preprocessor in general.  This would be a particularly odious use of the Preprocessor programming.

Even moreso because you'd need to do it in your header file, and all your clients would be affected by the Preprocessor substitution of a C/C++ keyword.  Very likely including the OS header files, which would break the platform API.

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -fdefault-integer-8 in c
  2010-03-10 14:54         ` John (Eljay) Love-Jensen
@ 2010-03-10 18:35           ` José Luis García Pallero
  0 siblings, 0 replies; 8+ messages in thread
From: José Luis García Pallero @ 2010-03-10 18:35 UTC (permalink / raw)
  To: John (Eljay) Love-Jensen; +Cc: gcc-help

El día 10 de marzo de 2010 15:54, John (Eljay) Love-Jensen
<eljay@adobe.com> escribió:
> Hi José,
>
>> Would be possible to use something like #define int long in the code.
>
> That would be possible.  (Along the same lines as "It would be possible to kill a fly using a 12 PW orbital satellite laser.")
>
> I strongly discourage such a solution.
>
> From a C (or C++) point of view, such a solution would be "very bad".  I would rank it in the top ten worst coding practices for C/C++, were such to be used.
>
> I am rather biased against programming in the Preprocessor in general.  This would be a particularly odious use of the Preprocessor programming.
>
> Even moreso because you'd need to do it in your header file, and all your clients would be affected by the Preprocessor substitution of a C/C++ keyword.  Very likely including the OS header files, which would break the platform API.
>
> Sincerely,
> --Eljay
>

OK, I see.
I have been seen some cblas implementations in order to imitate the
behaviour in my code.

In cblas implementation from GSL and ATLAS, all indexes is defined as
int in cblas.h, as the cblas standard says. But in GotoBLAS2 the
indexes of the functions in cblas.h are defines as blasint type, that
is defined in common.h as:

#if defined(OS_WINDOWS) && defined(__64BIT__)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif

#ifdef USE64BITINT
typedef BLASLONG blasint;
#else
typedef int blasint;
#endif

As you said me in your first reply, one way is via typedef, that would
be probably the way that I will implement in my code.

-fdefault-integer-8 in C probably make the things easier in this case,
but ISO C standard says (if I remember correctly) that int must have a
maximum of 4 bytes length.

-- 
*****************************************
José Luis García Pallero
jgpallero@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-03-10 18:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-09 22:41 -fdefault-integer-8 in c José Luis García Pallero
2010-03-10  0:15 ` Nicholas Sherlock
2010-03-10 11:56 ` John (Eljay) Love-Jensen
2010-03-10 12:36   ` José Luis García Pallero
2010-03-10 13:16     ` John (Eljay) Love-Jensen
2010-03-10 14:43       ` José Luis García Pallero
2010-03-10 14:54         ` John (Eljay) Love-Jensen
2010-03-10 18:35           ` José Luis García Pallero

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).