Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    5

    [C++]Domanda teorica:lvalue

    Ciao ragazzi!
    probabilmente la mia domanda vi sembrerà banale o stupida ma sto studiando programmazione in C++ per un esame...dunque causa forza maggiore.

    Da alcune slides del mio professore in cui spiega cosa sia un lvalue si legge:

    " Una funzione che restituisce un riferimento:
    – Il tipo di ritorno di una funzione può essere un riferimento, a condizione che il valore riferimento, a condizione che il valore restituito non sia un lvalue locale alla
    funzione .
    – Questa restrizione impone che lvalue esiste effettivamente dopo che la funzione è terminata " ...ma che diamine significa?!?!
    In un'altra slide scrive che gli lvalue che nn possono andare a sinistra sono detti non modificabili!
    Ma quindi questo significa che ci sono lvalue che non vanno a sinistra dell'operatore di assegnazione?
    Poi mi piacerebbe capire cosa si intende per lvalue modificabili ed lvalue non modificabili.

    Aiuto! ho una gran confusione in testa.
    Grazie mille a tutti
    Nereide

  2. #2
    Expressions that refer to memory locations are called "l-value" expressions. An l-value represents a storage region's "locator" value, or a "left" value, implying that it can appear on the left of the equal sign (=). L-values are often identifiers.

    Expressions referring to modifiable locations are called "modifiable l-values." A modifiable l-value cannot have an array type, an incomplete type, or a type with the const attribute. For structures and unions to be modifiable l-values, they must not have any members with the const attribute. The name of the identifier denotes a storage location, while the value of the variable is the value stored at that location.

    An identifier is a modifiable l-value if it refers to a memory location and if its type is arithmetic, structure, union, or pointer. For example, if ptr is a pointer to a storage region, then *ptr is a modifiable l-value that designates the storage region to which ptr points.

    Any of the following C expressions can be l-value expressions:
    • An identifier of integral, floating, pointer, structure, or union type
    • A subscript ([ ]) expression that does not evaluate to an array
    • A member-selection expression (–> or .)
    • A unary-indirection (*) expression that does not refer to an array
    • An l-value expression in parentheses
    • A const object (a nonmodifiable l-value)

    The term "r-value" is sometimes used to describe the value of an expression and to distinguish it from an l-value. All l-values are r-values but not all r-values are l-values.
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.