Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
hola tanto tiempo
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 28 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Daniel Gutson  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 1:54 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 15:54:21 -0300
Local: Thurs, Feb 23 2012 1:54 pm
Subject: hola tanto tiempo

char c = f();

if ( c == 0xff )
{
    ...

}

else
{
    ...

}

   qué onda?

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Gutson  
View profile  
 More options Feb 23 2012, 1:55 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 15:55:04 -0300
Local: Thurs, Feb 23 2012 1:55 pm
Subject: Re: hola tanto tiempo

pd: a ver si contestan nuevos, en vez de los sospechosos de siempre

On Thu, Feb 23, 2012 at 3:54 PM, Daniel Gutson <danielgut...@gmail.com>wrote:

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile  
 More options Feb 23 2012, 1:59 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Thu, 23 Feb 2012 15:59:12 -0300
Local: Thurs, Feb 23 2012 1:59 pm
Subject: Re: [cppba] hola tanto tiempo
Uhhh que malo que sos....

Esto es MUUUY sutil

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Gutson  
View profile  
 More options Feb 23 2012, 2:01 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 16:01:20 -0300
Local: Thurs, Feb 23 2012 2:01 pm
Subject: Re: [cppba] hola tanto tiempo

y un bug real que le ocurrió a un amigo y me preguntó hoy porque no
entendía qué pasaba :)

On Thu, Feb 23, 2012 at 3:59 PM, Fernando Cacciola <

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ramiro del Corro  
View profile  
 More options Feb 23 2012, 2:09 pm
From: Ramiro del Corro <ramiro.del.co...@gmail.com>
Date: Thu, 23 Feb 2012 11:09:44 -0800
Local: Thurs, Feb 23 2012 2:09 pm
Subject: Re: [cppba] hola tanto tiempo

Puede que sea por si char es signed, 0xFF deberia ser -1, pero como 0xFF es
int, lo usa como 255 y nunca entraria al if? Muy frio?

On Thu, Feb 23, 2012 at 11:01 AM, Daniel Gutson <danielgut...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Gutson  
View profile  
 More options Feb 23 2012, 2:29 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 16:29:45 -0300
Local: Thurs, Feb 23 2012 2:29 pm
Subject: Re: [cppba] hola tanto tiempo

On Thu, Feb 23, 2012 at 4:09 PM, Ramiro del Corro <

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Gutson  
View profile  
 More options Feb 23 2012, 2:30 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 16:30:58 -0300
Local: Thurs, Feb 23 2012 2:30 pm
Subject: Re: [cppba] hola tanto tiempo

Ahora bien, cómo lo arreglarían?

On Thu, Feb 23, 2012 at 4:29 PM, Daniel Gutson <danielgut...@gmail.com>wrote:

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ramiro del Corro  
View profile  
 More options Feb 23 2012, 2:39 pm
From: Ramiro del Corro <ramiro.del.co...@gmail.com>
Date: Thu, 23 Feb 2012 11:39:35 -0800
Local: Thurs, Feb 23 2012 2:39 pm
Subject: Re: [cppba] hola tanto tiempo

usando unsigned char o (char)0xFF?

On Thu, Feb 23, 2012 at 11:30 AM, Daniel Gutson <danielgut...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Gutson  
View profile  
 More options Feb 23 2012, 2:41 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 16:41:05 -0300
Local: Thurs, Feb 23 2012 2:41 pm
Subject: Re: [cppba] hola tanto tiempo

Ahí no la clavaste en el ángulo.

Alguien más?

On Thu, Feb 23, 2012 at 4:39 PM, Ramiro del Corro <

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ramiro del Corro  
View profile  
 More options Feb 23 2012, 3:03 pm
From: Ramiro del Corro <ramiro.del.co...@gmail.com>
Date: Thu, 23 Feb 2012 12:03:20 -0800
Local: Thurs, Feb 23 2012 3:03 pm
Subject: Re: [cppba] hola tanto tiempo

Agrego otra de este estilo que me paso:

char a = 0xFF (esto salia de un ifstream binario)
int b = a;

Mi idea era q b == 0xFF :(
On Feb 23, 2012 4:41 PM, "Daniel Gutson" <danielgut...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Gutson  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 3:05 pm
From: Daniel Gutson <danielgut...@gmail.com>
Date: Thu, 23 Feb 2012 17:05:52 -0300
Local: Thurs, Feb 23 2012 3:05 pm
Subject: Re: [cppba] hola tanto tiempo

es lo mismo castear de cualquier cosa a cualquier cosa? (en términos de
dirección)

Si T1 y T2 son dos tipos de datos, siempre va a ser lo mismo para estos
propósitos castear en cualquier dirección?

On Thu, Feb 23, 2012 at 5:03 PM, Ramiro del Corro <

--
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doc  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 8:50 pm
From: Doc <castano.rodr...@gmail.com>
Date: Thu, 23 Feb 2012 17:50:35 -0800 (PST)
Local: Thurs, Feb 23 2012 8:50 pm
Subject: Re: hola tanto tiempo
Yo creo que no.
Tomando "estos propósitos" como comparar por igualdad, si tenés:
float a = 1.5f;
int b = 1;
if(b == int(a))
{
    ...

}

entra en el if,
mientras que con:
if(float(b) == a)
{
    ....

}

no entra en el if.

Volviendo a la pregunta original, yo usaría una mascara y compararía
por igualdad:

if((c&0xff) == 0xff)

On Feb 23, 5:05 pm, Daniel Gutson <danielgut...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile  
 More options Feb 23 2012, 8:53 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Thu, 23 Feb 2012 22:53:01 -0300
Local: Thurs, Feb 23 2012 8:53 pm
Subject: Re: [cppba] Re: hola tanto tiempo
> if((c&0xff) == 0xff)

Y eso qué da si c, de tipo char, vale -1 ?

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eduardo  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 9:05 pm
From: Eduardo <abdula...@gmail.com>
Date: Thu, 23 Feb 2012 18:05:35 -0800 (PST)
Local: Thurs, Feb 23 2012 9:05 pm
Subject: Re: hola tanto tiempo
Permiso caballeros. Jamás escribo pero siempre los leo.

En problemas de ese estilo siempre me saca del agua el código
assembler generado.

En este caso es:

   ;    if ( c == 0xff )
   ;
?live1@32: ; EAX = c
        movsx     eax,al
        cmp       eax,255
        jne       short @2

Donde se vé por qué vamos muertos. Al char lo pasa a 32bit extendiendo
el signo y después compara con 255.

O bien c se define como unsigned char o hacemos if ( c == -1 )


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 9:31 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Thu, 23 Feb 2012 23:31:30 -0300
Local: Thurs, Feb 23 2012 9:31 pm
Subject: Re: [cppba] Re: hola tanto tiempo
Hola Eduardo,

[esto tiene tela para cortar]

Vayamos por parte:

> o hacemos if ( c == -1 )

Usar -1 en lugar de 0xFF es decididamente un paso adelante, pero, no
es solo por lo que vos empiricamente viste que pasa:

Veamos:

(1)

char c = -1 ;

char magic = 0xFF ;

if ( c == magic )

Ya no hay ninguna conversión implícita haciendo lio, pero, anda?

NO lo prueben porque van a llegar a la conclusión equivocada, salvo
que tengan un máquina poco convensional.

Por otro lado, tu version es equivalente a esto:

(2)

 char c = -1 ;

 if ( (int)(c) == -1 )

Seguro que anda?

De nuevo no lo prueben, salvo que el compilador perfectamente legal lo
hayan hecho a proposito para demotrar que....ç

> O bien c se define como unsigned char

Cuando esten resultos los dos puntos anteriores vuelvo sobre esto.

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carlos Cattaneo  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 9:39 pm
From: Carlos Cattaneo <carloscatta...@yahoo.com>
Date: Thu, 23 Feb 2012 18:39:50 -0800 (PST)
Local: Thurs, Feb 23 2012 9:39 pm
Subject: Re: [cppba] Re: hola tanto tiempo

Es corecto que haga eso el compilador haga eso ya que la comparación la tiene que hacer entre enteros con signo.
El literal 0xff es un entero con signo y por lo tanto tiene que primero promover a c a un entero con signo y luego comparar.
 
Para solucionar esta tema de manera portable debemos hacer que la constante sea un literal de tipo char, es decir

________________________________
From: Eduardo <abdula...@gmail.com>
To: CyC++ Buenos Aires <cppba@googlegroups.com>
Sent: Thursday, February 23, 2012 11:05 PM
Subject: [cppba] Re: hola tanto tiempo

Permiso caballeros. Jamás escribo pero siempre los leo.

En problemas de ese estilo siempre me saca del agua el código
assembler generado.

En este caso es:

  ;    if ( c == 0xff )
  ;
?live1@32: ; EAX = c
    movsx    eax,al
    cmp      eax,255
    jne      short @2

Donde se vé por qué vamos muertos. Al char lo pasa a 32bit extendiendo
el signo y después compara con 255.

O bien c se define como unsigned char o hacemos if ( c == -1 )

--
¿Eres miembro de "CyC++ Buenos Aires" verdad? Si no lo eres, has recibido este mesaje por error.
En caso de duda visita "http://groups.google.com/group/cppba"

\xhh
 
con lo que la línea de código quedaría:
 
if ( c == \xff )
 
Una aclaración adicional:
 
char, unsigned char y signed char son 3 tipos diferentes. Durante la conversión de char a int el compilador es libre de elegir si lo considera con signo o no, por lo tanto comparar contra -1 no es portable.
 
Saludos
Carlos Cattaneo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 9:51 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Thu, 23 Feb 2012 23:51:34 -0300
Local: Thurs, Feb 23 2012 9:51 pm
Subject: Re: [cppba] Re: hola tanto tiempo
Hola Carlos tanto tiempo!

Dije que esto daba para rato :)

> con lo que la línea de código quedaría:

> if ( c == \xff )

Todavía quedan 'huecos' por resolver aún en esta versión.

Fijate la devolución a Eduardo.

> Una aclaración adicional:

> char, unsigned char y signed char son 3 tipos diferentes. Durante
> la conversión de char a int el compilador es libre de elegir si lo considera
> con signo o no, por lo tanto comparar contra -1 no es portable.

Ahí nos vamos acercando.
Efectivamente el -1 no es portable si convertimos el char a int.

Por otro lado, técnicamente, la dicotomía existe aún mas allá de la
conversión a entero.
Es decir:

char c0 = -1 ;
unsigned  char c1 = -1 ;
signed chat c2 = -1 ;

if ( c0 == c1 )
if ( c0 == c2 ) ;

Alguno de los if() da true? Cuál?

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eduardo  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 10:24 pm
From: Eduardo <abdula...@gmail.com>
Date: Thu, 23 Feb 2012 19:24:37 -0800 (PST)
Local: Thurs, Feb 23 2012 10:24 pm
Subject: Re: hola tanto tiempo
On Feb 23, 11:31 pm, Fernando Cacciola <fernando.cacci...@gmail.com>
wrote:

> Por otro lado, tu version es equivalente a esto:

> (2)

>  char c = -1 ;

>  if ( (int)(c) == -1 )

> Seguro que anda?

Hola Fernando!

Eso anda según mi entender (y mi método de control :-) ),  aunque
debido al (int) tiene que hacer una conversión antes de comparar. De
la otra forma compara directamente dos registros de 8bits.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eduardo  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 10:30 pm
From: Eduardo <abdula...@gmail.com>
Date: Thu, 23 Feb 2012 19:30:08 -0800 (PST)
Local: Thurs, Feb 23 2012 10:30 pm
Subject: Re: hola tanto tiempo

On Feb 23, 11:51 pm, Fernando Cacciola <fernando.cacci...@gmail.com>
wrote:

> char c0 = -1 ;
> unsigned  char c1 = -1 ;
> signed chat c2 = -1 ;

> if ( c0 == c1 )
> if ( c0 == c2 ) ;

> Alguno de los if() da true? Cuál?

Dependerá de cómo el compilador asigna por defecto  a char,  si signed
o unsigned.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 10:31 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Fri, 24 Feb 2012 00:31:38 -0300
Local: Thurs, Feb 23 2012 10:31 pm
Subject: Re: [cppba] Re: hola tanto tiempo

> Hola Fernando!

> Eso anda según mi entender (y mi método de control :-) ),

OK, una pista entonces.

NO lo prueben porque les va a andar.. y sin embargo eso no quiere decir nada :)

P.S.:

Otra pista... C y C++, a diferencia de muchos otros lenguajes, está
pensado para permitir al programador escribir un fuente y correr el
programa resultante en cualquier cosa capaz de ser programada, y
entonces, esta DEFINIDO de un modo que haga eso posible.
Decimos entonces que la *especificación* del lenguaje (según un
determinado estandard) dice que las cosas son de uno y/o otro modo, y
es eso lo que debe ser considerado para decidir si el programa que
escribimos hace *garantizadamente* esto o aquello.

Saludos

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 10:33 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Fri, 24 Feb 2012 00:33:15 -0300
Local: Thurs, Feb 23 2012 10:33 pm
Subject: Re: [cppba] Re: hola tanto tiempo

> Dependerá de cómo el compilador asigna por defecto  a char,  si signed
> o unsigned.

ESO.

Entonces?

si char  c = -1 ;

(int)(c) da o no da -1??

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eduardo  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 10:47 pm
From: Eduardo <abdula...@gmail.com>
Date: Thu, 23 Feb 2012 19:47:04 -0800 (PST)
Local: Thurs, Feb 23 2012 10:47 pm
Subject: Re: hola tanto tiempo

On Feb 24, 12:33 am, Fernando Cacciola <fernando.cacci...@gmail.com>
wrote:

> > Dependerá de cómo el compilador asigna por defecto  a char,  si signed
> > o unsigned.

> ESO.

> Entonces?

> si char  c = -1 ;

> (int)(c) da o no da -1??

Ja ja!  Lo que pasa es que recién cuando contesté esto caí en lo que
apuntabas.

En mi pequeño mundo x86 son los chars e ints signados por defecto,
pero en el mundo de los microcontroladores son unsigned por defecto.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 11:07 pm
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Fri, 24 Feb 2012 01:07:06 -0300
Local: Thurs, Feb 23 2012 11:07 pm
Subject: Re: [cppba] Re: hola tanto tiempo

> En mi pequeño mundo x86 son los chars e ints signados por defecto,
> pero en el mundo de los microcontroladores son unsigned por defecto.

Ojo que complemento del x86 no es solo el mundo de los microcontroladores (*)

Por otro lado:

Lo que debemos saber es que:

un char puede, "internamente", ser un signed char o un unsigned char,
según lo defina el compilador.

(*)

Miren este listado de "arquitecturas" *que son todavía suficientemente
relevantes:

http://svn.boost.org/svn/boost/sandbox/predef/libs/predef/doc/html/pr...

P.S.: Todavía falta el tema del  (signed char)(-1) vs 0xFF

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doc  
View profile   Translate to Translated (View Original)
 More options Feb 23 2012, 11:46 pm
From: Doc <castano.rodr...@gmail.com>
Date: Thu, 23 Feb 2012 20:46:23 -0800 (PST)
Local: Thurs, Feb 23 2012 11:46 pm
Subject: Re: hola tanto tiempo
Impresionante todo lo que se aprende.

Preguntas:
¿cuál es la razón o ventaja que tiene permitir que char pueda ser
interpretado como signed o como unsigned?
¿Por qué no exigir que el programador especifique el signo?
¿pasa lo mismo con integer, signed integer y unsigned integer?

Siguiendo con este razonamiento creería que (signed char)(-1) == 0xFF
sería falso, ya que 0xFF es un entero positivo (¿las constantes por
default son enteros con signo, no?) y se castea el (signed char) -1 a
signed integer, manteniendo el valor (-1).

On Feb 24, 1:07 am, Fernando Cacciola <fernando.cacci...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Cacciola  
View profile   Translate to Translated (View Original)
 More options Feb 24 2012, 7:00 am
From: Fernando Cacciola <fernando.cacci...@gmail.com>
Date: Fri, 24 Feb 2012 09:00:45 -0300
Local: Fri, Feb 24 2012 7:00 am
Subject: Re: [cppba] Re: hola tanto tiempo

> Preguntas:
> ¿cuál es la razón o ventaja que tiene permitir que char pueda ser
> interpretado como signed o como unsigned?

Buena pregunta:

signed/unsigned char son tipos enteros que sirven para representar
números enteros con o sin signo, mientras que char a secas, aunque
puede ser usado del mismo modo (tal como ocurre en la práctica),
existe en sí mismo como el tipo de dato que representa de un byte.

Es decir, un bloque de memoria, es decir el *storage* que le
corresponde a un *objeto* (o lvalue en C), está definido como una
secuencia de chars (y no como una secuencia de signed char o unsigned
char). Resulta entonces que necesitamos del tipo char como un tipo
diferente a signed/unsigned char para referir a bloques de memoria.

Ahora bien, si  tenemos que tener esos tres tipos, y char tiene que
ser el que corresponde a un byte, porqué especificar si tiene que ser
con o sin signo en lugar de dejar a la implementación (o sea el
compilador) decidirlo?

Por otro lado, uno podria pensar que char podría no tener nada que ver
con signed or unsigned char y tener en cambio su propia definicion
independiente (que de todos modos no especificaria si puede o no
representar números negativos (*) para no forzar al compilador
innecesariamete)
.Net por ejemplo distingue explicitamente uno de otros:

http://msdn.microsoft.com/en-us/magazine/bb984984.aspx

Aunque hace explícito el tema del signo: byte es unsigned mientras que
sbyte es signed (en mi opninión esto es un error, pero...)

> ¿Por qué no exigir que el programador especifique el signo?

Acá está el quiz de la cuestón:

el verdadero propósito de char es,k o debería ser en mi opinión,
representar un byte. Y la arquitectura define el byte como se le da la
gana, incluso en cuanto a la cantidad de bits (sizeof(char)==8 no es
siempre cierto!)

Ahora, si el programador quiere representar números pequeños, debe, o
puede al menos, usar signed char or unsigned char, con lo cual está
especificando el signo como decis.

Que en la práctica se abuse de char para, por ejemplo, representar
caracteres en un archivo o string, es posiblemente un accidente
cultural (tal vez en K&R no había todavía signed char/unsigned char?
sería interesante investigar esto)

> ¿pasa lo mismo con integer, signed integer y unsigned integer?

NO

Para cualquier otro tipo de dato entero, signed está implicito:

 typeof(signed int)==typeof(int), lo mismo para short, long, etc...

> Siguiendo con este razonamiento creería que (signed char)(-1) == 0xFF
> sería falso, ya que 0xFF es un entero positivo
> (¿las constantes por
> default son enteros con signo, no?)

Los *literales* (no constantes) son de un determinado tipo que depende
del la forma del literal, y sí, para el caso de "solo un número" (mas
allá de que sea decimal o hexdecimal), el tipo es signed int, que es
lo mismo que int.

1u por otro lado es un unsgined int, etc..

> y se castea el (signed char) -1 a
> signed integer, manteniendo el valor (-1).

Hmm, en realidad me equivoqué y quise preguntar por:

(unsigned char)(-1) == 0xFF

Eso es o no cierto?

[todavía hay un tema más que del cual no se habló para nada todavía]

Saludos

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 28   Newer >
« Back to Discussions « Newer topic     Older topic »