Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [C++]Puntatori e Casting

    Ciao, mi è capito più volte, mentre leggevo uan guida sulla programmazione di rete di trovare dentro una funzione questo argomento:

    int bind(int sockfd, struct sockaddr *mioindir, int lunghindr)
    E fino a qual il prototipo è OK, una funziona che accetta come argomento un puntatore di uans truttura sockaddr.

    La funzione viene chiamata in questo modo:

    bind (sd,(struct sockaddr*) &server_addr, sizeof(server_Addr));

    (struct sockaddr*) &server_addr Che cosa è questo?

    Converte la dove è conservato l'indirizzo ottenuto con &, in un puntatore?

    Ma quando una funzione accetta un puntatore non ci va inserito &variabile?
    A che cosa serve quella cosa fatta?


    Ciao

  2. #2


    Ma una classe C++ sui socket non esiste?

  3. #3
    Utente di HTML.it L'avatar di netarrow
    Registrato dal
    Apr 2004
    Messaggi
    1,425
    Originariamente inviato da SkOrPiOn`87


    Ma una classe C++ sui socket non esiste?
    che io sappia windows ha winsok che credo usi le classi, sennò MFC sempre su windows che è un astrazione.
    Su linux mai trovato niente, per un periodo ho cercato un'astrazione che con qualche define fosse portabile sia fra win e *nix ma non ho trovato. Quelle strutture che usa sono essenzialmente per il C più che per il C++ credo.

    Imparare è un'esperienza, tutto il resto è solo informazione. (Albert Einstein)

  4. #4
    Originariamente inviato da SkOrPiOn`87


    Ma una classe C++ sui socket non esiste?
    La libreria standard del C++ non fornisce alcuna classe per i socket (a differenza di Java)

    quindi se proprio vuoi una classe per i socket, devi cercare qualche libreria fatta da terze parti

    socket++
    http://freshmeat.net/projects/socketxx

    A proposito di librerie, ti segnalo Boost
    http://sourceforge.net/projects/boost

    Perché è importante Boost?
    Perché è in discussione l'integrazione di alcune sue librerie nella libreria standard del C++.
    Ten Boost libraries will be included in the C++ Standards Committee's upcoming C++ Standard Library Technical Report as a step toward becoming part of a future C++ Standard.

    Ho contrassegnato quelle che ritengo più utili
    • any - Safe, generic container for single values of different value types, from Kevlin Henney.
    • array - STL compliant container wrapper for arrays of constant size, from Nicolai Josuttis.
    • assign - Filling containers with constant or generated data has never been easier, from Thorsten Ottosen.
    • bind and mem_fn - Generalized binders for function/object/pointers and member functions, from Peter Dimov.
    • call_traits - Defines types for passing parameters, from John Maddock, Howard Hinnant, et al.
    • compatibility - Help for non-conforming standard libraries, from Ralf Grosse-Kunstleve and Jens Maurer.
    • compressed_pair - Empty member optimization, from John Maddock, Howard Hinnant, et al.
    • concept check - Tools for generic programming, from Jeremy Siek.
    • config - Helps boost library developers adapt to compiler idiosyncrasies; not intended for library users.
    • conversion - Numeric, polymorphic, and lexical casts, from Dave Abrahams and Kevlin Henney.
    • crc - Cyclic Redundancy Code, from Daryle Walker.
    • date_time- Date-Time library from Jeff Garland.
    • dynamic_bitset - A runtime sized version of std::bitset from Jeremy Siek and Chuck Allison.
    • enable_if - Selective inclusion of function template overloads, from Jaakko Järvi, Jeremiah Willcock, and Andrew Lumsdaine.
    • filesystem - Portable paths, iteration over directories, and other useful filesystem operations, from Beman Dawes.
    • format - Type-safe 'printf-like' format operations, from Samuel Krempp.
    • function - Function object wrappers for deferred calls or callbacks, from Doug Gregor.
    • functional - Enhanced function object adaptors, from Mark Rodgers.
    • graph - Generic graph components and algorithms, from Jeremy Siek and a University of Notre Dame team.
    • integer - Headers to ease dealing with integral types.
    • interval - Extends the usual arithmetic functions to mathematical intervals, from Guillaume Melquiond, Herv´ Brönnimann and Sylvain Pion.
    • in_place_factory, typed_in_place_factory- Generic in-place construction of contained objects with a variadic argument-list, from Fernando Cacciola.
    • io state savers - Save I/O state to prevent jumbled data, from Daryle Walker.
    • iterators - Iterator construction framework, adaptors, concepts, and more, from Dave Abrahams, Jeremy Siek, and Thomas Witt.
    • lambda - Define small unnamed function objects at the actual call site, and more, from Jaakko Järvi and Gary Powell.
    • math - Several contributions in the domain of mathematics, from various authors.
    • math/common_factor - Greatest common divisor and least common multiple, from Daryle Walker.
    • math/octonion - Octonions, from Hubert Holin.
    • math/quaternion - Quaternions, from Hubert Holin.
    • math/special_functions - Mathematical special functions such as atanh, sinc, and sinhc, from Hubert Holin.
    • minmax - standard library extensions for simultaneous min/max and min/max element computations, from Hervé Brönnimann.
    • mpl - Template metaprogramming framework of compile-time algorithms, sequences and metafunction classes, from Aleksey Gurtovoy.
    • multi_array - Multidimensional containers and adaptors for arrays of contiguous data, from Ron Garcia.
    • multi_index - Containers with multiple STL-compatible access interfaces, from Joaquín M López Muñoz.
    • numeric/conversion - Optimized Policy-based Numeric Conversions, from Fernando Cacciola.
    • operators - Templates ease arithmetic classes and iterators, from Dave Abrahams and Jeremy Siek.
    • optional - Discriminated-union wrapper for optional values, from Fernando Cacciola.
    • pool - Memory pool management, from Steve Cleary.
    • preprocessor - Preprocessor metaprogramming tools including repetition and recursion, from Vesa Karvonen and Paul Mensonides.
    • program_options - Access to configuration data given on command line, in config files and other sources, from Vladimir Prus.
    • property map - Concepts defining interfaces which map key objects to value objects, from Jeremy Siek.
    • python - Reflects C++ classes and functions into Python, from Dave Abrahams.
    • random - A complete system for random number generation, from Jens Maurer.
    • range - A new infrastructure for generic algorithms that builds on top of the new iterator concepts, from Thorsten Ottosen.
    • rational - A rational number class, from Paul Moore.
    • ref - A utility library for passing references to generic functions, from Jaako Järvi, Peter Dimov, Doug Gregor, and Dave Abrahams.
    • regex - Regular expression library, from John Maddock.
    • serialization - Serialization for persistence and marshalling, from Robert Ramey
    • signals - managed signals & slots callback implementation, from Doug Gregor.
    • smart_ptr - Five smart pointer class templates, from Greg Colvin, Beman Dawes, Peter Dimov, and Darin Adler.
    • static_assert - Static assertions (compile time assertions), from John Maddock.
    • spirit - LL parser framework represents parsers directly as EBNF grammars in inlined C++, from Joel de Guzman and team.
    • string_algo - String algorithms library, from Pavol Droba
    • test - Support for simple program testing, full unit testing, and for program execution monitoring, from Gennadiy Rozental.
    • thread - Portable C++ multi-threading, from William Kempf.
    • timer - Event timer, progress timer, and progress display classes, from Beman Dawes.
    • tokenizer - Break of a string or other character sequence into a series of tokens, from John Bandela.
    • tribool - 3-state boolean type library, from Doug Gregor.
    • tuple - Ease definition of functions returning multiple values, and more, from Jaakko Järvi.
    • type_traits - Templates for fundamental properties of types, from John Maddock, Steve Cleary, et al.
    • uBLAS - Basic linear algebra for dense, packed and sparse matrices, from Joerg Walter and Mathias Koch.
    • utility - Class noncopyable plus checked_delete(), checked_array_delete(), next(), prior() function templates, plus base-from-member idiom, from Dave Abrahams and others.
    • value_initialized - Wrapper for uniform-syntax value initialization, from Fernando Cacciola, based on the original idea of David Abrahams.
    • variant - Safe, generic, stack-based discriminated union container, from Eric Friedman and Itay Maman.

  5. #5
    Utente di HTML.it L'avatar di /dev/null
    Registrato dal
    May 2004
    Messaggi
    1,936

    Re: [C++]Puntatori e Casting

    Originariamente inviato da SkOrPiOn`87
    Ciao, mi è capito più volte, mentre leggevo uan guida sulla programmazione di rete di trovare dentro una funzione questo argomento:

    int bind(int sockfd, struct sockaddr *mioindir, int lunghindr)
    E fino a qual il prototipo è OK, una funziona che accetta come argomento un puntatore di uans truttura sockaddr.

    La funzione viene chiamata in questo modo:

    bind (sd,(struct sockaddr*) &server_addr, sizeof(server_Addr));

    (struct sockaddr*) &server_addr Che cosa è questo?

    Converte la dove è conservato l'indirizzo ottenuto con &, in un puntatore?

    Ma quando una funzione accetta un puntatore non ci va inserito &variabile?
    A che cosa serve quella cosa fatta?


    Ciao
    Di solito &server_addr viene castato in struct sockaddr* perche' di solito e' una variabile di tipo struct sockaddr_in, ed e' sempre consigliato eseguire il cast anche con il C... (lo stesso discorso vale anche per la funzione accept() )
    Ultima modifica ad opera dell'utente /dev/null il 01-01-0001 alle 00:00

  6. #6
    In poche parole Boost, che cosa fa?

    Perdonami l'ignoranza

  7. #7

    Re: Re: [C++]Puntatori e Casting

    Originariamente inviato da /dev/null
    Di solito &server_addr viene castato in struct sockaddr* perche' di solito e' una variabile di tipo struct sockaddr_in, ed e' sempre consigliato eseguire il cast anche con il C... (lo stesso discorso vale anche per la funzione accept() )
    Se non lo faccio che cosa cambia? Perchè è peggio?


    Grazie

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.